[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1556
  • Last Modified:

Powershell WINS\DNS settings

I have got this to change DNS\WINS settings

# Unhash DNS sections if required.

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

foreach($NIC in $NICs) {
#$DNSServers = "2.2.2.1","2.2.2.2"
#$NIC.SetDNSServerSearchOrder($DNSServers)
#$NIC.SetDynamicDNSRegistration("TRUE")
$NIC.SetWINSServer("1.1.1.111","1.1.1.222")
}
}

function GetFileName {
$computer = "c:\temp\serverlist.txt"
return $computer
}

$f = GetFileName
Get-Content $f | foreach {SetDNSWINS}

This does it on all adapters how can I get it to only change WINS address on adapters that already have a value there?  The reason is because of things like cluster heart beat etc?

Thanks
0
korin123
Asked:
korin123
  • 2
  • 2
1 Solution
 
jwarnkenCommented:
Give this a try
# Unhash DNS sections if required.

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

foreach($NIC in $NICs) {
#$DNSServers = "2.2.2.1","2.2.2.2"
#$NIC.SetDNSServerSearchOrder($DNSServers)
#$NIC.SetDynamicDNSRegistration("TRUE")
if(!($NIC.WINSPrimaryServer -eq $null)){$NIC.SetWINSServer("1.1.1.111","1.1.1.222")}
}
}

function GetFileName {
$computer = "c:\temp\serverlist.txt"
return $computer
}

$f = GetFileName
Get-Content $f | foreach {SetDNSWINS}

Open in new window

0
 
korin123Author Commented:
Thanks a lot for the quick reply.

To confirm will this only change adapters with current WINS settings and leave blank one's blank.
i will try tomorrow in the lab


Thanks again
0
 
jwarnkenCommented:
The change will look for a non blank entry in the Primary Wins Server. If it is not blank it will update the wins servers. If it is blank no change is made.
0
 
korin123Author Commented:
Thanks a lot work a treat :)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now