Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Export Powershell results to CSV

$
0
0

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.txt


foreach($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
    }

}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>