PoshCode Archive  Artifact [1415c24a21]

Artifact 1415c24a21d3324fd3b8a4e61bf5791d3c76217bda6a46f73b4416bbf5d59eac:

  • File Ping-Host.ps1 — part of check-in [c4978fca4f] at 2018-06-10 14:05:34 on branch trunk — Simple function that pings a host and returns a boolean. (user: dragonmc77 size: 640)

# encoding: ascii
# api: powershell
# title: Ping-Host
# description: Simple function that pings a host and returns a boolean.
# version: 0.1
# type: function
# author: dragonmc77
# license: CC0
# function: Ping-Host
# x-poshcode-id: 599
# x-archived: 2014-08-01T17:24:54
# x-published: 2009-09-23T19:12:00
#
#
function Ping-Host {param(	[string]$HostName,
							[int32]$Requests = 3)
	
	for ($i = 1; $i -le $Requests; $i++) {
		$Result = Get-WmiObject -Class Win32_PingStatus -ComputerName . -Filter "Address='$HostName'"
		Start-Sleep -Seconds 1
		if ($Result.StatusCode -ne 0) {return $FALSE}
	}
	return $TRUE
}