Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update_dns_ip.ps1
$Computerlist = get-content "\\vmware-host\Shared Folders\Documents\RGA\dns_server_updates.txt"
$dnsservers =@("192.168.0.9","192.168.0.12")
$cred = Get-Credential rga.local\it-services
foreach ($computername in $computerlist) {
$result = get-wmiobject win32_pingstatus -filter "address='$computername'"
if ($result.statuscode -eq 0) {
$remoteNic = get-wmiobject -class win32_networkadapter -computer $computername -Credential $cred | where-object {$_.Name -eq "vmxnet3 Ethernet Adapter"}
$index = $remotenic.index
$DNSlist = $(get-wmiobject win32_networkadapterconfiguration -computer $computername -Credential $cred -Filter ‘IPEnabled=true’ | where-object {$_.index -eq $index}).dnsserversearchorder
$priDNS = $DNSlist | select-object -first 1
Write-host "Changing DNS IP's on $computername" -b "Yellow" -foregroundcolor "black"
$change = get-wmiobject win32_networkadapterconfiguration -computer $computername -Credential $cred | where-object {$_.index -eq $index}
$change.SetDNSServerSearchOrder($DNSservers) | out-null
$changes = $(get-wmiobject win32_networkadapterconfiguration -computer $computername -Credential $cred -Filter ‘IPEnabled=true’ | where-object {$_.index -eq $index}).dnsserversearchorder
Write-host "$computername's Nic1 Dns IPs $changes"
}
else {
Write-host "$Computername is down cannot change IP address" -b "Red" -foregroundcolor "white"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.