My desired result is to display the DNS servers listed in the IP config of a computer in a CSV format. I am getting the DNS servers ok, with the simple WMI call, but I'm having trouble isolating the individual IP's so I can generate the CSV style output. I was trying to add the $line.DNSServerSearchOrder to an array and working with the elements that way, but couldn't come with anything that worked. Here is what I have so far. You could ditch a lot of this by supplying your own computername of course.
cls
import-module ActiveDirectory
Write-Host "Searching AD for servers"
$rtn_servers = Get-ADComputer -Filter {OperatingSystem -like "*server*"} -Properties "operatingsystem", "OperatingSystemServicePack" | Select Name,OperatingSystem,OperatingSystemServicePack
Write-Host "Located servers, getting information on each server."
Write-Host ""
foreach ($computername in $rtn_servers)
{
$return_dns = Get-WmiObject -Class win32_networkadapterconfiguration DNSServerSearchOrder -ComputerName $computername.Name
foreach ($DNSserver in $return_dns)
{
if ($DNSserver.DNSServerSearchOrder -ne $null)
{
$computername.Name
$DNSserver.DNSServerSearchOrder
Write-Host ""
}
}
}
Any help is greatly appreciated!