Created
April 22, 2013 12:56
-
-
Save BenNeise/5434695 to your computer and use it in GitHub Desktop.
Uses WMI to ping a server, and returns TRUE if a status code of 0 is returned.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function IsPingable { | |
<# | |
.Synopsis | |
Pings a server and returns TRUE or FALSE. | |
.Description | |
Uses WMI to ping a server, and returns TRUE if a status code of 0 is returned, otherwise returns FALSE. Useful for quick checks to see if a server exists and is online. | |
.Parameter Computer | |
The computer's Hostname, FQDN, or IP to be pinged. | |
.Example | |
IsPingable -Computer "SERVER01" | |
Pings SERVER01 | |
.Notes | |
Ben Neise 12/03/13 | |
#> | |
Param ( | |
[Parameter( | |
Mandatory=$true, | |
Position=0 | |
)] | |
[string]$Computer = "" | |
) | |
$objPing = Get-WmiObject -Class Win32_PingStatus -Filter "Address='$Computer'" | |
If ($objPing.StatusCode -eq 0){ | |
$boolPingable=$true | |
} | |
Else { | |
$boolPingable=$false | |
} | |
Return $boolPingable | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment