Hi,
Following the thread “another-empty-pipe-error-when-export-csv-used/#post-10028”, I tried to use Dave Wyatt’s second option of “force a foreach loop to pipe its results somewhere (placing the loop into a subexpression, and piping the results of the subexpression to the next command)” and derived the following to see which of our organizations servers are no longer in DNS. Unfortunately all I get is the screen display (helpful) and an empty file (not so much.):
$Names = import-csv -Path "C:\temp\AD_servers.csv" | % {$_.Name}
$(
Foreach ($name in $Names)
{
$Addresses = $null
try {
$Addresses = [System.Net.Dns]::GetHostAddresses("$Name").IPAddressToString
}
catch {
$Addresses = "Server IP cannot resolve."
}
foreach($Address in $addresses) {
write-host "$Name,"$Address
}
}
) |export-csv "C:\temp\result.csv"
Suggestions?
Thanks,
-Bob King