test-connection server | select-object *
returns many properties, among them StatusCode.
How can I return only this value?
My best guess would be
$r = test-connection server
$r.statuscode
but that doesn’t work.
How do I do it?
EDIT
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394350%28v=vs.85%29.aspx has more information about the statuscode I would like to receive.. No luck yet!
Test-Connectionby default will give you a collection (4System.Management.ManagementObjectobjects). It uses the Win32_PingStatus WMI class internally.Outputs:
So you can do this:
or this:
Don’t forget, some pings may fail so if you just check one it may not necessary mean there’s no connection.
You could also try calling
Win32_PingStatusdirectly like this: