Monthly Archive

Categories

Quick ping

If you’ve used ping before you’ll know that it normally returns four replies from the target.  In PowerShell we have Test-Connection which does the same job. It also normally returns four replies.

When I’m working with remote machines I often want to check they are available before sending a command – especially a WMI command that can take a long time to time out.

 

001
002
003
004
005
006
007
"rslaptop01", "127.0.0.1" | 
foreach {
    if (Test-Connection $_ -Count 1) {
        Get-WmiObject -ComputerName $_ -Class Win32_LogicalDisk -Filter "DriveType='3'" |
        select SystemName, DeviceID, Size, FreeSpace
    }
}

 

To speed up the process use the –Count parameter on test-connection and only get 1 reply.  Quick test to see if he system is there and then run the rest of the code

Leave a Reply