You are currently viewing PowerShell Script to add Multiple IP Address

PowerShell Script to add Multiple IP Address

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.

This Post Has 6 Comments

  1. Sergiu

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

  2. Rick Ly

    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

    1. Ardian Anggara

      Hello,
      Thank you. Could you please copy paste your code start from $iplist? I believe there is a typo and the ps failed to convert the list.

      1. Rick Ly

        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

        1. Ardian Anggara

          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