The Windows PowerShell command Set-NetIPAddress is a powerful tool for configuring network IP addresses. It can be used to configure both IPv4 and IPv6 addresses, and it can be used to set static or dynamic IP addresses. In this article, we’ll take a look at the syntax, parameters, inputs, outputs, examples, and tips for using the Set-NetIPAddress command.
Syntax
The syntax for the Set-NetIPAddress command is as follows:
Set-NetIPAddress [-InterfaceIndex]
Parameters
The Set-NetIPAddress command has the following parameters:
Parameter | Description |
---|---|
InterfaceIndex | The index of the network interface to configure. |
AddressFamily | The address family of the IP address to configure. Can be either IPv4 or IPv6. |
IPAddress | The IP address to configure. |
PrefixLength | The prefix length of the IP address. |
DefaultGateway | The default gateway to use for the IP address. |
Type | The type of IP address to configure. Can be either Static or Dynamic. |
PassThru | If specified, the command will return the configured IP address. |
CimSession | The CIM session to use for the command. |
ThrottleLimit | The throttle limit for the command. |
AsJob | If specified, the command will run as a background job. |
WhatIf | If specified, the command will run in simulation mode. |
Confirm | If specified, the command will prompt for confirmation before running. |
Inputs
The Set-NetIPAddress command requires the following inputs:
- InterfaceIndex: The index of the network interface to configure.
- AddressFamily: The address family of the IP address to configure. Can be either IPv4 or IPv6.
- IPAddress: The IP address to configure.
- PrefixLength: The prefix length of the IP address.
- DefaultGateway: The default gateway to use for the IP address.
- Type: The type of IP address to configure. Can be either Static or Dynamic.
Outputs
The Set-NetIPAddress command has the following outputs:
- If the PassThru parameter is specified, the command will return the configured IP address.
Examples
The following example shows how to configure a static IPv4 address on the network interface with index 2:
Set-NetIPAddress -InterfaceIndex 2 -AddressFamily IPv4 -IPAddress 192.168.1.10 -PrefixLength 24 -DefaultGateway 192.168.1.1 -Type Static
The following example shows how to configure a dynamic IPv6 address on the network interface with index 3:
Set-NetIPAddress -InterfaceIndex 3 -AddressFamily IPv6 -IPAddress “2001:db8::1” -PrefixLength 64 -DefaultGateway “2001:db8::2” -Type Dynamic
Tips
When using the Set-NetIPAddress command, there are a few tips to keep in mind:
- Make sure to specify the correct interface index for the network interface you want to configure.
- Make sure to specify the correct address family for the IP address you want to configure.
- Make sure to specify the correct IP address and prefix length for the IP address you want to configure.
- Make sure to specify the correct default gateway for the IP address you want to configure.
- Make sure to specify the correct type for the IP address you want to configure.
Conclusion
The Windows PowerShell command Set-NetIPAddress is a powerful tool for configuring network IP addresses. It can be used to configure both IPv4 and IPv6 addresses, and it can be used to set static or dynamic IP addresses. By following the syntax, parameters, inputs, outputs, examples, and tips outlined in this article, you should be able to use the Set-NetIPAddress command with confidence.