I'm trying to export the results from my powershell script to a nice CSV that lists the FQDN and IP of a server from a text file list of FQDNs.
Here's what I have. I've seen lots of similar threads but my powershell fu is lacking. So far it works great for outputting content on the screen.
$Servers = Get-Content -Path C:\ServerList.txtforeach($Server in $Servers) {
try {
$hostname = [System.Net.DNS]::GetHostAddresses($Server)
Write-Host $Server " " $hostname
}
catch {
Write-Host
Write-Host $Server "did not resolve"
Write-Host
}
}