Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

List servers and their DNS server settings

183 views
Skip to first unread message

guv

unread,
Jun 8, 2010, 8:09:45 AM6/8/10
to

I am trying to get a list of server names and their primary and secondary
DNS server settings.

If I try the following command:

get-wmiobject Win32_networkadapterconfiguration -computername "servername |
select name, DNSServerSearchOrder

It would give me the specific servername and its dns addresses.

I know have a list of computernames which I would like to list out and their
DNSserversearchorder settings (DNS settings)

I tried putting the list of computernames in a text file by using
get-qadcomputer | export-csv C:\computername.txt -notype

Then I used the get-content command and the piped into the get-wmiobject
command like below:

$servers = Get-Content c:\computername.txt

ForEach ($server in $servers)
{ get-wmiobject Win32_networkadapterconfiguration -computername $server
| where{$_.IPEnabled -match "True"} | select-object
name,DNSServerSearchOrder

But when I run this command it fails with errors such as an empty pipe
element is not permitted. I dont know if the above script has any synatx
errors or what is the best way to get a list of servers and their dns server
settings.

Can anyone please advise


Chris Dent

unread,
Jun 8, 2010, 8:23:55 AM6/8/10
to

ForEach does not return output to the pipeline, although you can
work-around that be executing it as a script block. ForEach-Object does.
May as well skip the file as well.

Get-QADComputer | ForEach-Object {
Get-WmiObject Win32_NetworkAdapterConfiguration -Computername $_.Name
-Filter "IPEnabled=$True" |
Select-Object Name, DNSServerSearchOrder
}

HTH

Chris

guv

unread,
Jun 8, 2010, 9:35:21 AM6/8/10
to
If I run the script :

Get-Content c:\computername.txt | `

ForEach-Object {

Get-WMIObject Win32_NetworkAdapterConfiguration -Computername $_ | `

Where-Object {$_.IPEnabled -match "True"} | `

Select-Object -property DNSHostName,DNSServerSearchOrder }

And in the computername.txt file I list the servers as :

server1

server2.

On the command line it displays the dnshostname and the dnsserversearchorder
as IP address values.

But when i import the script to a csv file like if i called the script
dns.ps1 and then run the following command:

./dns.ps1 | export.csv c:\servers.csv

the dnsserversearchorder values are displayed as System.String[] in the csv
file and not the IP addresses of the DNS servers. The DNShostname is
displayed fine. Any reason why this is happening and how i can the ipaddress
values in a csv or txt file to be displayed.

"guv" <guv@> wrote in message news:OUM$1NwBLH...@TK2MSFTNGP02.phx.gbl...

Chris Dent

unread,
Jun 8, 2010, 10:52:41 AM6/8/10
to

This will get you a list of servers in a string rather than as an array.

Select-Object DnsHostName, @{n='DNSServers';e={
"$($_.DnsServerSearchOrder)" }}

0 new messages