Asked by:
Script to Chnage DNS configuration of Remote Windows servers

Question
-
I am using this script to change the DNS settings on remote Windows servers:
$computer = get-content C:\sl.txt
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
Foreach($NIC in $NICs) {
Write-Host "DNS Servers before change:"
$NIC.DNSServerSearchOrder$DNSServers = “198.102.234.125",”198.102.234.126"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
}
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
Write-Host "DNS Servers after change:"
$NICs.DNSServerSearchOrderBut, getting this as output:
__GENUS : 2 __CLASS : __PARAMETERS __SUPERCLASS : __DYNASTY : __PARAMETERS __RELPATH : __PROPERTY_COUNT : 1 __DERIVATION : {} __SERVER : __NAMESPACE : __PATH : ReturnValue : 91
I have also tried the script providing the Credentials, but still same error.
All replies
-
-
-
I only want to Change the Primary or Secondary DNS server's address. Then, what change I need to make?
And Can I check and change the DNS Configuration using a single script, Please Comment?
\_(ツ)_/
-
For instructions on using the WMI method see: https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/setdnsserversearchorder-method-in-class-win32-networkadapterconfiguration
\_(ツ)_/