scripting multiple IP address on a closed network RRS feed

  • General discussion

  • im looking to find a way to script multiple IP address from a central server the script below works great, one i found her on msn however it only works per machines power shell, if someone has a moment is there a way to modify the randomness of an IP address set to static or DHCP on many machines at once or should i be looking at this differently i have even thought about using 

    Apart from modifying network adapter properties from the Control Panel, you can also use the Command line tool to enable disable Network Interface Card.

    1. Press Windows key + X, click Command Prompt (Admin).  
    2. In the elevated command prompt, copy and paste the command below, and press Enter. This will show you all network adapter names on your PC. netsh interface show interface  
    3. To enable NIC type, the following command: netsh interface set interface "network_adapter_name" admin=enable (e.g netsh interface set interface "MyEthernet" admin=enable)  

    To disable NIC type, the following command: netsh interface set interface "network_adapter_name" admin=disable (e.g netsh interface set interface "MyEthernet" admin=disable)

     i still think it is a little too manual any suggestions would be welcome

    $IPAddress=$(Read-Host "Specify your IP address (ie")   
    $InterfaceIndex=$(Read-Host "Enter InterfaceIndex (ie 3) NOTE: Enter 'Show' for help")   
    foreach ($InterfaceIndex in $InterfaceIndex){   
            if ($InterfaceIndex -eq "Show" -eq "show") {   
                     Get-NetIPAddress | Format-List -Property InterfaceAlias,InterfaceIndex    
                    if ($InterfaceIndex -eq "Show" -eq "show") {   
                        $InterfaceIndex=$(Read-Host "Enter InterfaceIndex")   
                    if (-Not ($InterfaceIndex -eq "Show" -eq "show"))    
    $SubnetMask=$(Read-Host "Enter the subnet mask in bits (ie 24 =")   
    $DefaultGateway=$(Read-Host "Enter your Default Gateway (ie")   
    $DNSAddresses=$(Read-Host "Set DNS Server Address/Addresses (ie")   
    New-NetIPAddress -IPAddress $IPAddress -InterfaceIndex $InterfaceIndex -PrefixLength $SubnetMask -DefaultGateway $DefaultGateway   
    Set-DnsClientServerAddress -InterfaceIndex $InterfaceIndex -ServerAddresses $DNSAddresses   
    $Servers = $DefaultGateway,$DNSAddresses    
    $Ping=$(Read-Host "Do You want me to Ping your Default Gateway and DNS Servers? Yes/No")   
    if ($Ping -eq "Yes" -eq "yes") {   
        foreach ($Server in $Servers) {   
                   if (Test-Connection -ComputerName $Server -Count 2 -Quiet) {   
                        Write-Host "$Server is alive and Pinging " -ForegroundColor Green 
                            else {   
                                     Write-Warning "$Server seems dead not Pinging"          
                        if ($Ping -eq "No" -eq "no") {   
                                    Write-Host "Good bye!" 
                                    elseif (-Not ($Ping -eq "Yes" -eq "yes"))    
    Read-Host "Press any key to close..." 

    i have also found this command for netsh

    FOR /L %A IN (10,1,20) DO netsh interface ipv4 add address “Local Area Connection” 192.168.1.%A

    looks like i can add multiple domains add address, but not sure how to script this

    • Edited by Kadmiels Monday, November 11, 2019 6:40 PM
    • Changed type Bill_Stewart Tuesday, April 14, 2020 5:12 PM
    • Moved by Bill_Stewart Tuesday, April 14, 2020 5:12 PM Unanswerable drive-by question
    Monday, November 11, 2019 6:01 PM

All replies

  • You have numerous coding errors like:

    if ($Ping -eq "No" -eq "no") {  

    "-eq" is not case sensitive.  This is unnecessary.


    Monday, November 11, 2019 7:52 PM
  • still looking for a way to set this up for multiple computers, or create a script that will allow it to auto DHCP across the nework to get its own IP 
    Wednesday, November 20, 2019 1:39 PM
  • Your question doesn't make any sense; sorry.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, November 20, 2019 3:08 PM