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)

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 

Here's a Microsoft article that covers this topic: http://blogs.technet.com/b/danstolts/archive/2012/01/31/using-powershell-to-get-or-set-networkadapterconfiguration-view-and-change-network-settings-including-dhcp-dns-ip-address-and-more-dynamic-and-static-step-by-step.aspx

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.