Change static IP WINS on remote computers with Powershell

I have a request from my manager to change the static IP address information for a list of 20 or 30 computers. I was trying to figure out how to do it using PowerShell.

So I found a script online that looks like it's what I'm going for but it's got a few bugs and I can't figure them all out.

function Set-DNSWINS 
    {
        #Get NICS via WMI
        $NICs = Get-WmiObject 
        -Class Win32_NetworkAdapterConfiguration 
        -ComputerName $_
        -Filter "IPEnabled=TRUE"

        foreach($NIC in $NICs) 
        {
            $DNSServers = "12.34.5.67","76.54.3.21"
            $NIC.SetDNSServerSearchOrder($DNSServers)
            $NIC.SetDynamicDNSRegistration("TRUE")
            $NIC.SetWINSServer("10.1.4.116", "10.16.5.204")
        }
    }

function Get-FileName 
	{
		$computer = Read-Host "Filename of computer names?"
		return $computer
	}

$f = Get-FileName
Get-Content $f | foreach {Set-DNSWINS}
It coughs up the prompt and I'm not sure why:

cmdlet Get-WmiObject at command pipeline position 1
Supply values for the following parameters:
Class:

Any help would be greatly appreciated. Thank you

Source: http://www.virtu-al.net/2008/08/22/change-dns-and-wins-on-multiple-servers/


  • Edited by Mauricem 16 hours 59 minutes ago Added link
June 26th, 2015 10:11am

$NICs = Get-WmiObject  Win32_NetworkAdapterConfiguration  -ComputerName $_  -Filter 'IPEnabled=TRUE'

If you get more than ne NIC then this will fail.You would be best off by setting a permanent reservation for these and let DGHCP manage all of this.

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 10:25am

Hi Maurice,

the Get-WmiObject command does not recognize the parameters specified in the next lines, since nobody told it to. Try this edit:

function Set-DNSWINS 
{
    #Get NICS via WMI
    $NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ -Filter "IPEnabled=TRUE"

    foreach($NIC in $NICs) 
    {
        $DNSServers = "12.34.5.67","76.54.3.21"
        $NIC.SetDNSServerSearchOrder($DNSServers)
        $NIC.SetDynamicDNSRegistration("TRUE")
        $NIC.SetWINSServer("10.1.4.116", "10.16.5.204")
    }
}

function Get-FileName 
{
    $computer = Read-Host "Filename of computer names?"
    return $computer
}

$f = Get-FileName
Get-Content $f | foreach {Set-DNSWINS}

Cheers,
Fred

June 26th, 2015 10:27am

These are all on separate lines which is the issue

 #Get NICS via WMI
        $NICs = Get-WmiObject 
        -Class Win32_NetworkAdapterConfiguration 
        -ComputerName $_
        -Filter "IPEnabled=TRUE"

Need to either put all parameters on a single line like

 #Get NICS via WMI
 $NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ -Filter "IPEnabled=TRUE"

Or use the backtic ( ` )

 #Get NICS via WMI
        $NICs = Get-WmiObject `
        -Class Win32_NetworkAdapterConfiguration `
        -ComputerName $_ `
        -Filter "IPEnabled=TRUE"

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 10:27am

Either move the get-wmi command all onto one line or use the backtic - 

$NICs = Get-WmiObject  `
        -Class Win32_NetworkAdapterConfiguration `
        -ComputerName $_ `
        -Filter "IPEnabled=TRUE"


$NICs = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $_ -Filter "IPEnabled=TRUE"

Edit: Late to the party.
  • Edited by Braham20 16 hours 37 minutes ago
June 26th, 2015 10:29am

That's a great idea. I agree, but my manager feels otherwise. Can't argue with the big dog.
Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 11:54am

That worked! The original script had a weird character when I tried to copy and paste, so I just took them out.
June 26th, 2015 11:57am

Thanks to everyone for the help! But it looks like the script is a bust. It only outputs a list of details about the WMI system properties. Any ideas on how I can use a script to change the WINS settings?
Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 12:05pm

$NIC.SetWINSServer("10.1.4.116", "10.16.5.204")

This sets WINS statically but if the interface is DHCP then it may get reset.


June 26th, 2015 12:28pm

https://msdn.microsoft.com/en-us/library/aa393624(v=vs.85).aspx

You also need to check the return value to see why it is failing.  Read the docs.

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 12:29pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics