Skip to content

Instantly share code, notes, and snippets.

@BenNeise
Created April 22, 2013 12:56
Show Gist options
  • Save BenNeise/5434695 to your computer and use it in GitHub Desktop.
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.
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