Solved

Powershell WINS\DNS settings

Posted on 2011-03-16
4
1,550 Views
Last Modified: 2012-05-11
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
Comment
Question by:korin123
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
jwarnken earned 500 total points
ID: 35149671
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
 

Author Comment

by:korin123
ID: 35150110
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
 
LVL 8

Expert Comment

by:jwarnken
ID: 35150223
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
 

Author Closing Comment

by:korin123
ID: 35154500
Thanks a lot work a treat :)
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question