PING PONG :)
Below script will display the result on
console.
$PingMachines = Gc "C:\MachineList.txt"
ForEach($MachineName In $PingMachines)
{$PingStatus = Gwmi Win32_PingStatus
-Filter "Address = '$MachineName'" |
Select-Object StatusCode
If ($PingStatus.StatusCode -eq 0)
{Write-Host $MachineName -Fore
"Green"}
Else
{Write-Host $MachineName -Fore
"Red"}}
Note: copy and paste the above
script into text file and save it as Pingclient.ps1
Get-Content "C:\ MachineList.txt"
| ForEach-Object {
if(Test-Connection -ComputerName $_
-Quiet -Count 1) {
New-Object -TypeName PSCustomObject
-Property @{
VMName = $_
'Ping Status' = 'Ok'
}
} else {
New-Object -TypeName PSCustomObject
-Property @{
VMName = $_
'Ping Status' = 'Powered OFF'
}
}
} | Export-Csv -Path "C:\PingStatus.csv"
–NoTypeInformation
Note:
copy and paste
the above script into text file and save it as Pingclients.ps1