Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Forked from alexinnes/ConstantPingToServer.ps1
Last active August 29, 2015 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/67eb5d4d4e48eb5d7cea to your computer and use it in GitHub Desktop.
Save IISResetMe/67eb5d4d4e48eb5d7cea to your computer and use it in GitHub Desktop.
#
# Ping-Forever.ps1
#
# Modified version of alexinnes/ConstantPingToServer.ps1 (https://gist.github.com/alexinnes/b2076c88700020af3963)
#
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$ComputerName,
[string]$LogDirectory = 'C:\ping logs\'
)
# File name based on date
$FileName = '{0:dd-MM-yyyy}.log' -f (Get-Date)
$FilePath = Join-Path -Path $LogDirectory -ChildPath $FileName
# If the directory doesn't exist, create it.
if (-not(Test-Path $LogDirectory)) {
New-Item -ItemType Directory -Path $LogDirectory
}
if($PSBoundParameters.ContainsKey('LogDirectory')){
$PSBoundParameters.Remove('LogDirectory')
}
# Ping it!
do {
Test-Connection @PSBoundParameters | Out-File $FilePath -Append -Force -Encoding default
} while ($true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment