PowerShell Script to add Multiple IP Address

6
10451
PowerShell

Adding multiple IP Addresses on the windows server using a graphical interface is really a pain as each IP Address need to be assigned manually. Through this article, I will show you how to add multiple IP Addresses using PowerShell command.

First, you need to get the Interface Index or Interface Alias of the NIC Interface. Below is the powershell command to get the Interface Index or Interface Alias.

Get-NetAdapter | Select Name, InterfaceIndex
Get-NetAdapter

For the example, Y want to assign the IP 10.100.0.20 to 10.100.0.50 to the Interface named “Ethernet“. Below is the complete PowerShell command to do that.

workflow add-ipaddress {
	Param($Iplist)
	foreach -parallel ($ip in $Iplist){
		New-NetIPAddress -InterfaceIndex 7 -IPAddress $ip -PrefixLength 27
	}
}
$Iplist = 20..50 | % {"10.100.0.$_"}
add-ipaddress $Iplist

We hope this article can help you to add multiple IP Addresses using PowerShell command. If you liked this article, then please share with the others. You can also find us on Twitter and Facebook.

6 COMMENTS

  1. $Iplist = 11..90 | % {“192.168.60.$_”}
    foreach ($ip in $Iplist) {New-NetIPAddress -InterfaceIndex 13 -IPAddress $ip -PrefixLength 24}

  2. this isn’t working for me, getting
    add-ipaddress : Cannot process argument transformation on parameter ‘Iplist’. Cannot convert value to type System.String.
    At line:9 char:15
    + add-ipaddress $Iplist
    + ~~~~~~~
    + CategoryInfo : InvalidData: (:) [add-ipaddress], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,add-ipaddress

      • PS C:\WINDOWS\system32> workflow add-ipaddress {
        Param( [string]$Iplist )
        foreach -parallel ($ip in $Iplist){
        New-NetIPAddress -InterfaceIndex 27 -ipaddress $ip -PrefixLength 24
        }
        }
        $Iplist = 46..100 | % {“10.250.216.$_”}
        add-ipaddress $Iplist
        add-ipaddress : Cannot process argument transformation on parameter ‘Iplist’. Cannot convert value to type System.String.
        At line:9 char:15
        + add-ipaddress $Iplist
        + ~~~~~~~
        + CategoryInfo : InvalidData: (:) [add-ipaddress], ParameterBindingArgumentTransformationException
        + FullyQualifiedErrorId : ParameterArgumentTransformationError,add-ipaddress

        • Dear Rick,
          I’ve reviewed my code again and just noticed the $iplist is shouldn’t on string data type, you need to remove [string] word on the workflow. I’ve also fixed my post. you can also use the Sergiu’s command to simplify, here is I requoted
          $Iplist = 46..100 | % {“10.250.216.$_”}
          foreach ($ip in $Iplist) {New-NetIPAddress -InterfaceIndex 27 -IPAddress $ip -PrefixLength 24}

LEAVE A REPLY

Please enter your comment!
Please enter your name here