Quick PowerShell script to check DNS settings on all servers

I wanted to decommission some old Domain Controllers. I needed to make sure that other servers weren’t pointing to theses old DCs for DNS. I wrote this quick PowerShell script to loop through all servers and get their DNS search order.

$AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"}
ForEach ($Server in $AllServers){
$Result=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $Server.Name 
$output = new-object PSObject 
$output | add-member NoteProperty "ComputerName" $Server.Name
$output | add-member NoteProperty "DNSServerSearchOrder" $Result.DNSServerSearchOrder
$output
}

Hope that helps some one, or me when we moce to the next version of DCs.


Posted

in

,

by

Comments

One response to “Quick PowerShell script to check DNS settings on all servers”

  1. Vic Avatar
    Vic

    Ran this script on Windows Server 2012 R2 and got the following error. Can you help?
    I need a PS script that collects DNS settings on servers in a legacy domain. And then, I will need a script that changes DNS settings to the new servers post AD upgrade.

    PS C:\scripts> .\check_dns_on_servers.ps1
    At C:\scripts\check_dns_on_servers.ps1:1 char:59
    + $AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*& …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:1 char:80
    + $AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*& …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:3 char:72
    + $Result=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPE …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:3 char:96
    + … nabled = ‘True’" -Property DNSServerSearchOrder -ComputerName $Server.Name
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:5 char:35
    + $output | add-member NoteProperty "ComputerName" $Server.Name
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:5 char:53
    + $output | add-member NoteProperty "ComputerName" $Server.Name
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:6 char:35
    + $output | add-member NoteProperty "DNSServerSearchOrder" $Result.DNSSe …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    At C:\scripts\check_dns_on_servers.ps1:6 char:61
    + $output | add-member NoteProperty "DNSServerSearchOrder" $Result.DNSSe …
    + ~
    The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
    quotation marks (“&”) to pass it as part of a string.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : AmpersandNotAllowed