PoshCode Archive  Artifact [17c40f0c87]

Artifact 17c40f0c87178d053d9c630cbd2a790f325bf5d7fe9534adc3b448fb5df52b4c:

  • File Log-Lost-Pings.ps1 — part of check-in [7f777d28b7] at 2018-06-10 14:07:24 on branch trunk — This script uses /n Software’s NetCmdlets, specifically the cmdlet “send-ping”, to continually ping a host, and log to a file whenever connectivity is lost. (user: Jacob Saaby Nielsen size: 1177)

# encoding: ascii
# api: powershell
# title: Log Lost Pings
# description: This script uses /n Software’s NetCmdlets, specifically the cmdlet “send-ping”, to continually ping a host, and log to a file whenever connectivity is lost.
# version: 1.0
# author: Jacob Saaby Nielsen
# license: CC0
# x-poshcode-id: 607
# x-archived: 2016-05-29T07:46:11
# x-published: 2009-09-26T09:17:00
#
#
# Logpings.ps1
# Version: 1.0
# Author: Jacob Saaby Nielsen
# Author E-Mail: jsy@systematic.com
# Purpose: Repeatedly ping a host, document lost pings to a logfile
# Syntax: .\Logpings hostname interval (where interval is a value representing seconds)
# Requirements: /n Software's NetCmdlets http://www.nsoftware.com/powershell/

$PingedHost = $Args[0]
$PingTime = $Args[1]
$LogPath = 'c:\'
$KillSwitch = 1

while ($KillSwitch -ne 0)
{
	Send-Ping $PingedHost
	if ($PingedHost.Status -ne "OK")
		{
			'Lost connectivity at: ' + $(Get-Date -format "dd-MM-yyyy @ hh:mm:ss") | Out-File $($LogPath + $(Get-Date -format "dd-MM-yyyy") + '.log') -noClobber -append
			$Error.Clear()
			Start-Sleep $PingTime
		}
	else
		{
			Start-Sleep $PingTime
		}
}