This script use WMI to ping a list of computers. Only specific OS are pinged.
Script (with Microsoft Active Directory module loaded : import-module activedirectory) :
$ping = new-object System.Net.NetworkInformation.Ping $list = Get-ADComputer -LDAPFilter "(|(operatingsystem=Windows XP*)(operatingsystem=Windows 7*)(operatingsystem=Windows Vista*))" ForEach ($b in $list) { $strQuery = "select * from win32_pingstatus where address = '" + $b.name + "'" $wmi = Get-WmiObject -Query $strQuery if ($wmi.statuscode -eq 0) {$b.name + " (" + $b.OSName + ") : alive"} else {$b.name + " (" + $b.OSName + ") : not reachable"} }
Script (with Quest Active Directory module) :
$ping = new-object System.Net.NetworkInformation.Ping $list = Get-QADComputer -OSName "Windows XP*","Windows Vista*","Windows 7*" ForEach ($b in $list) { $strQuery = "select * from win32_pingstatus where address = '" + $b.name + "'" $wmi = Get-WmiObject -Query $strQuery if ($wmi.statuscode -eq 0) {$b.name + " (" + $b.OSName + ") : alive"} else {$b.name + " (" + $b.OSName + ") : not reachable"} }
Reference : Win32_PingStatus class
The Win32_PingStatus WMI class represents the values returned by the standard ping command. More information about ping can be found in RFC 791.
Starting with Windows Vista, Win32_PingStatus can return data for computers that have both IPv4 addresses and IPv6 addresses.
Windows Server 2003 and Windows XP: Win32_PingStatus only returns data for computers running IPv4. For more information, see IPv6 and IPv4 Support in WMI.
The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order, not MOF order.
Syntax
class Win32_PingStatus { string Address; uint32 BufferSize = 32; boolean NoFragmentation = FALSE; uint32 PrimaryAddressResolutionStatus; string ProtocolAddress = ""; string ProtocolAddressResolved = ""; uint32 RecordRoute = 0; boolean ReplyInconsistency; uint32 ReplySize; boolean ResolveAddressNames = FALSE; uint32 ResponseTime; uint32 ResponseTimeToLive; string RouteRecord[]; string RouteRecordResolved[]; String SourceRoute = ""; uint32 SourceRouteType = 0; uint32 StatusCode; uint32 Timeout = 1000; uint32 TimeStampRecord[]; string TimeStampRecordAddress[]; string TimeStampRecordAddressResolved[]; uint32 TimeStampRoute = 0; uint32 TimeToLive = 80; uint32 TypeofService = 0; };
Members
The Win32_PingStatus class has these types of members:
Properties
The Win32_PingStatus class has these properties.
- Address
-
- Data type: string
- Access type: Read-only
- Qualifiers: Key
Value of the address requested. The form of the value can be either the computer name (“wxyz1234”), IPv4 address (“192.168.177.124”), or IPv6 address (“2010:836B:4179::836B:4179”).
- BufferSize
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
Buffer size sent with the ping command. The default value is 32.
- NoFragmentation
-
- Data type: boolean
- Access type: Read-only
- Qualifiers: Key
If TRUE, “Do not Fragment” is marked on the packets sent. The default is FALSE, not fragmented.
- PrimaryAddressResolutionStatus
-
- Data type: uint32
- Access type: Read-only
Status of the address resolution process. If successful, the value is 0 (zero). Any other value indicates an unsuccessful address resolution.
- ProtocolAddress
-
- Data type: string
- Access type: Read-only
- Qualifiers: MaxLen (4096)
Address that the destination used to reply. The default is “”.
- ProtocolAddressResolved
-
- Data type: string
- Access type: Read-only
- Qualifiers: MaxLen (4096)
Resolved address corresponding to the ProtocolAddress property. The default is “”.
- RecordRoute
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
How many hops should be recorded while the packet is in route. The default is 0 (zero).
- ReplyInconsistency
-
- Data type: boolean
- Access type: Read-only
Inconsistent reply data is reported.
- ReplySize
-
- Data type: uint32
- Access type: Read-only
Represents the size of the buffer returned.
- ResolveAddressNames
-
- Data type: boolean
- Access type: Read-only
- Qualifiers: Key
Command resolves address names of output address values. The default is FALSE, which indicates no resolution.
- ResponseTime
-
- Data type: uint32
- Access type: Read-only
Time elapsed to handle the request.
- ResponseTimeToLive
-
- Data type: uint32
- Access type: Read-only
Time to live from the moment the request is received.
- RouteRecord
-
- Data type: string array
- Access type: Read-only
Record of intermediate hops.
- RouteRecordResolved
-
- Data type: string array
- Access type: Read-only
Resolved address that corresponds to the RouteRecord value.
- SourceRoute
-
- Data type: String
- Access type: Read-only
- Qualifiers: Key
Comma-separated list of valid Source Routes. The default is “”.
- SourceRouteType
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
Type of source route option to be used on the host list specified in the SourceRoute property. If a value outside of the ValueMap is specified, then 0 (zero) is assumed. The default is 0 (zero).
Value Meaning - 0
None - 1
Loose Source Routing - 2
Strict Source Routing - StatusCode
-
- Data type: uint32
- Access type: Read-only
Ping command status codes.
- Timeout
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
Time-out value in milliseconds. If a response is not received in this time, no response is assumed. The default is 1000 milliseconds.
- TimeStampRecord
-
- Data type: uint32 array
- Access type: Read-only
Record of time stamps for intermediate hops.
- TimeStampRecordAddress
-
- Data type: string array
- Access type: Read-only
Intermediate hop that corresponds to the TimeStampRecord value.
- TimeStampRecordAddressResolved
-
- Data type: string array
- Access type: Read-only
Resolved address that corresponds to the TimeStampRecordAddress value.
- TimeStampRoute
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
How many hops should be recorded with time stamp information while the packet is in route. A time stamp is the number of milliseconds that have passed since midnight Universal Time (UT). If the time is not available in milliseconds or cannot be provided with respect to midnight UT, then any time may be inserted as a time stamp, provided the high order bit of the Timestamp property is set to 1 (one) to indicate the use of a nonstandard value. The default is 0 (zero).
- TimeToLive
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
Life span of the ping packet in seconds. The value is treated as an upper limit. All routers must decrement this value by 1 (one). When this value becomes 0 (zero), the packet is dropped by the router. The default value is 80 seconds. The hops between routers rarely take this amount of time.
- TypeofService
-
- Data type: uint32
- Access type: Read-only
- Qualifiers: Key
Type of service that is used. The default value is 0 (zero).
Value Meaning - 0
Normal - 2
Minimize Monetary Cost - 4
Maximize Reliability - 8
Maximize Throughput - 16
Minimize Delay
Remarks
This class does not support enumeration. For more information about implementing WMI enumeration in C++, see Enumerating WMI. In scripting, Win32_PingStatus does not support the enumeration calls SWbemServices.InstancesOf or SWbemObject.Instances. It does support SWbemServices.ExecQuery and SWbemServices.GetObject.
Examples
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.
For C++ code examples, see WMI C++ Application Examples.