Some PowerShell code to change DNS servers on a set of windows boxes....

Might be useful - have I posted this before???  Maybe not with any Try/Catch stuff...

Make a list of machines names in a txt file "c:\scripts\machinelist.txt" - is my example...

Copy the following into a ps1 file (enable scripts to run!) and run as an admin on all the machines in the list (domain admin?)...done.

#
# Script to set the DNS Settings on a Windows box
#

$computerList = get-content c:\scripts\machinelist.txt
$date = Get-Date -format D
$log = "---------------- Log Starting : $date ----------------`r`n"

ForEach($computer in $computerList){

# Do some logging??
try{
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer -ErrorAction stop
        $NICs = $NICs | where{$_.IPEnabled -eq “TRUE” -and $_.Description -match "Wireless"}

ForEach($NIC in $NICs){

$DNSServers = ”1.2.3.4","1,2,3,5",“1.2.3.6"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
}
$logLine = "$computer updated OK`r`n"
}
catch{
$logLine = "*** $computer failed to update ***`r`n"
}
$log += $logLine
}
# Write the log
$log | Out-File c:\scripts\DNS-Change_Log.txt -append


Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Security Policy 1001