# 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
		}
}
