Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
In this article, we will explore the usage of the New-NetIPAddress cmdlet in PowerShell with practical examples specifically tailored for the Windows environment. New-NetIPAddress is a powerful command that allows us to create and configure IP addresses for network interfaces on Windows machines. Understanding how to use this cmdlet is crucial for any Windows engineer or system administrator, as it enables efficient network management and troubleshooting.
Examples:
Example 1: Creating a New IP Address
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.1.100" -PrefixLength 24 -DefaultGateway "192.168.1.1"
In this example, we use the New-NetIPAddress cmdlet to create a new IP address for the network interface with the alias "Ethernet." We specify the IP address as "192.168.1.100" with a subnet mask of 255.255.255.0 (equivalent to a prefix length of 24). Additionally, we set the default gateway to "192.168.1.1". This command will assign the specified IP address to the interface and configure the necessary routing settings.
Example 2: Modifying an Existing IP Address
$ipAddress = Get-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.1.100"
$ipAddress | Set-NetIPAddress -IPAddress "192.168.1.200" -PrefixLength 24 -DefaultGateway "192.168.1.1"
In this example, we first retrieve the existing IP address configuration for the network interface with the alias "Ethernet" and the IP address "192.168.1.100". We store this information in the $ipAddress variable. Then, we use the Set-NetIPAddress cmdlet to modify the IP address to "192.168.1.200" with a subnet mask of 255.255.255.0 and set the default gateway to "192.168.1.1". This command allows us to change the IP address settings without deleting and recreating the entire configuration.
Example 3: Removing an IP Address
Remove-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.1.100"
In this example, we use the Remove-NetIPAddress cmdlet to remove the IP address "192.168.1.100" from the network interface with the alias "Ethernet". This command effectively deletes the specified IP address from the interface, allowing it to be assigned to another interface or removed from the network altogether.