PoshCode Archive  Artifact [f71d70a8aa]

Artifact f71d70a8aa98a96f1a6e2791b8ddb9df4ab238eda3cd9afa9e3ddd838d67ffa7:

  • File Ping-Host.ps1 — part of check-in [42aae22a1e] at 2018-06-10 13:31:49 on branch trunk — Simple function that pings a host and returns a boolean. (user: mafpc366 size: 639)

# encoding: ascii
# api: powershell
# title: Ping-Host
# description: Simple function that pings a host and returns a boolean.
# version: 0.1
# type: function
# author: mafpc366
# license: CC0
# function: Ping-Host
# x-poshcode-id: 3829
# x-archived: 2012-12-23T07:29:32
# x-published: 2012-12-19T04:17: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
}