Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#
# 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
You can’t perform that action at this time.