Skip to content

Instantly share code, notes, and snippets.

@flickerfly
Created November 30, 2016 20:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flickerfly/82eb8c37b0db4b16231b49f6205e6a4f to your computer and use it in GitHub Desktop.
Save flickerfly/82eb8c37b0db4b16231b49f6205e6a4f to your computer and use it in GitHub Desktop.
Check the DNS Settings for all Windows Servers
# Source: http://www.jbmurphy.com/2013/09/23/quick-powershell-script-to-check-dns-settings-on-all-servers/
# Could use error checking to not throw an alert when the server isn't accessible
$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
}
@flickerfly
Copy link
Author

Been a long time since I did Powershell stuff, but I think you could just modify the last line to $output | export-CSV or something like that.

@brucefordev
Copy link

Wow, didn't expect you to answer but you did. I will try that. Thank you so much!

@brucefordev
Copy link

I tried the last line to $output | export-csv "c:\dnssettings" but no results when I open the excel spreadsheet. Please let me know if you have any thoughts about it. Thanks for your help.

@eveningit
Copy link

Managed to get it working with csv like this:

$AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*" -and Enabled -eq 'True'}
$Servers = ForEach ($Server in $AllServers){

$Result=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $Server.Name

New-Object -TypeName PSObject -Property @{
ComputerName = $Server.Name -join ','
DNSServerSearchOrder = $Result.DNSServerSearchOrder -join ','

} | Select-Object ComputerName,DNSServerSearchOrder | Export-Csv -Path C:\Temp\ServerDNSSettings2.csv -NoTypeInformation -Append
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment