1: function Get-ping { 2: [CmdletBinding()]
3: PARAM
4: (
5: [Parameter(Position=1,
6: Mandatory=$false,
7: ValueFromPipeline = $true,
8: Helpmessage="The computer name")]
9: [string]
10: $computername="."
11: )
12: BEGIN
13: { 14: $result = @()
15: #set the erroractionpreference to SilentlyContinue.
16: #(We're not concerned about offline machines)
17: $erroractionpreference = "SilentlyContinue"
18: }
19: PROCESS
20: { 21: $object = new-object Object
22: $object| add-member Noteproperty PC $computername.ToUpper()
23: $ping = new-object System.Net.NetworkInformation.Ping
24: $Reply = $ping.send("$computername") 25: if ($Reply.status –eq “Success”)
26: { 27: $object| add-member Noteproperty Status `
28: -Value $reply.Address.IPAddressToString
29: }
30: else
31: { 32: $object| add-member Noteproperty Status Offline
33: }
34: #Add the result to the array
35: $result += $object
36: $object = $null
37:
38: }
39: END
40: { 41: $result
42: }
43: }