PowerShell for Windows Admins

May 21 2010   12:52PM GMT

Quick ping

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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
008
"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

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: