?
Solved

Powershell WINS\DNS settings

Posted on 2011-03-16
4
Medium Priority
?
1,554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
jwarnken earned 2000 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

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

770 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