# A script to change ip address without knowing the Network connection name

Let's suppose that I have some Pc with windows. Each of them has only 1 Local area connection , but I don't know the full name. Is possible to create a general script to change ip address for these pc ? I try to use netsh , but as I said I don't know the connection full name that it's required by netsh. ( Ip address , Default gateway , DNS server all are known and must be inside the script , only the connection name should be detected if possible).

Take a look at Powershell:

$activeNICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE # filter this more until you have the NIC that you really need Foreach($NIC in $activeNICs) {$ip = ($NIC.IPAddress[0])$gateway = $NIC.DefaultIPGateway$subnet = $NIC.IPSubnet[0]$dns = $NIC.DNSServerSearchOrder$NIC.EnableStatic($ip,$subnet)
$NIC.SetGateways($gateway)
$NIC.SetDNSServerSearchOrder($dns)
\$NIC.SetDynamicDNSRegistration("FALSE")
}

Just modify it to include your specific settings and remove what you don't need.

You can create and edit scripts in Powershell ISE (search for ise in the start menu). Once it works as you want, save it with the extension .ps1. You can run it with

powershell -executionpolicy bypass C:\path\to\script.ps1
• thank you , but in what kind of file should I put this code , .vbs , .bat....or ? – tiku Mar 18 '15 at 18:50
• Powershell is the successor of cmd and runs Powershell scripts that have the .ps1 file extension. For security reasons the default action when double clicking PS scripts is to open the file in notepad. I'll add how to run the script to my answer. – megamorf Mar 18 '15 at 19:01