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
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
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...
Select-Object DnsHostName, @{n='DNSServers';e={
"$($_.DnsServerSearchOrder)" }}