Discussion:
List servers and their DNS server settings
(too old to reply)
unknown
2010-06-08 12:09:45 UTC
Permalink
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
2010-06-08 12:23:55 UTC
Permalink
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
Post by unknown
I am trying to get a list of server names and their primary and secondary
DNS server settings.
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
$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
unknown
2010-06-08 13:35:21 UTC
Permalink
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.
Post by unknown
I am trying to get a list of server names and their primary and secondary
DNS server settings.
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
$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
2010-06-08 14:52:41 UTC
Permalink
This will get you a list of servers in a string rather than as an array.

Select-Object DnsHostName, @{n='DNSServers';e={
"$($_.DnsServerSearchOrder)" }}
Post by unknown
Get-Content c:\computername.txt | `
ForEach-Object {
Get-WMIObject Win32_NetworkAdapterConfiguration -Computername $_ | `
Where-Object {$_.IPEnabled -match "True"} | `
Select-Object -property DNSHostName,DNSServerSearchOrder }
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 | 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.
Post by unknown
I am trying to get a list of server names and their primary and secondary
DNS server settings.
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
$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
Loading...