Wednesday, September 25, 2013

Powershell: Ping List of Computers and Export the results to CSV

This script will ping a list of computers and then output the results into CSV.

Get-Content c:\test\computers.txt | ForEach-Object
    {
        if(Test-Connection -ComputerName $_ -Quiet -Count 1) {
            New-Object -TypeName PSCustomObject -Property @{
                ComputerName = $_
                'Ping Status' = 'Ok'
                }
    }
    else
    {
        New-Object -TypeName PSCustomObject -Property @{
            ComputerName = $_
            'Ping Status' = 'Failed'
        }  
    }
} | Export-Csv -Path c:\test\PingStatus.csv -NoTypeInformation

If you find this article useful please leave me a comment or click on an ad to show your support.

No comments :

Post a comment