PoshCode Archive  Artifact Content

Artifact 410cf4f545b194cb2c81e1308c8ea77763e80d977d27ec0fa6fc54dda19408d2:

  • File ping-check-using-dotNet.ps1 — part of check-in [4bb819e820] at 2018-06-10 12:57:05 on branch trunk — ping check using dotNet ping. pieced together from existing examples on the web. Had to use $erroractionpreference = “SilentlyContinue” to make it work on non-existing systems. Added to DNS check to prevent a few more errors. This is part of a script that queries an internal db and for every record does a ping to verify its online state (user: jkavanagh58 size: 1445)

# encoding: ascii
# api: powershell
# title: ping check using dotNet 
# description: ping check using dotNet ping.  pieced together from existing examples on the web.  Had to use $erroractionpreference = “SilentlyContinue” to make it work on non-existing systems.  Added to DNS check to prevent a few more errors.  This is part of a script that queries an internal db and for every record does a ping to verify its online state
# version: 0.1
# type: function
# author: jkavanagh58
# license: CC0
# x-poshcode-id: 1420
# x-archived: 2009-10-27T22:36:03
#
#
function dnsref ($computername) {
$ErrorActionPreference = "SilentlyContinue"
$testrun=$Null
trap { 
	Write-Host "ERROR: $computername does not exist in DNS" -fore Yellow
	Throw $_ }
$testrun=[net.dns]::GetHostByName($computername) 
if ($testrun -eq $Null){
	Write-Host "No DNS Record" }
else { 
	foreach ($alias in $testrun){
 			PingX($alias.addresslist)
 		}
	}
}
function PingX($ip) {
	$ErrorActionPreference="SilentlyContinue"
	$ping = New-Object System.Net.NetworkInformation.ping
	#trap {$_.Exception.Message ;$pingres = $_Exception.Message; continue}
	if ($_Exception.Message -eq $null) {
	$pingres = ($ping.send($ip)).Status | Out-Null
	Write-Host $computername - $ip is REACHABLE -background "GREEN" -foreground "BLACk"}
	else
	{Write-Host $computername - $ip is NOT reachable  -background "RED" -foreground "BLACk"}
	return $pingres
}