Powershell Ping Test
so ..you got a long list of servers on your AD ,but are all of them “alive”? ..and functioning..?
how you can check this issue ? there’s a really useful command named ‘Test-connection’.
for example we can use it this way –
1 2 3 4 5 6 |
$servername = Read-Host "Please Enter Server Name" $connection = Test-Connection -ComputerName $servername -Count 2 -BufferSize 5000 -TimeToLive 255 -Quiet -WarningAction SilentlyContinue if ($connection -ne "Running") {Write-Host "Cannot Connect Server $servername"} else {Write-Host "Server Online"} |
lets get back to the list we got before ..(Get-ADComputer -Filter ‘ObjectClass .. . )
we can use this command with a loop running on the list we got ,No ? Good Idea !
1 2 3 4 5 |
foreach ($Comp in $list) { if (Test-Connection $comp -Count 2 -BufferSize 5000 -TimeToLive 255 -Quiet -WarningAction SilentlyContinue) {Write-Host "$_ Computer Online"} else {"Computer Offline"} } |
You might also like with Test-Socket function.
(Visited 831 times, 1 visits today)