Skip to content

Instantly share code, notes, and snippets.

@TScalzott
Created August 15, 2019 12:53
Show Gist options
  • Save TScalzott/f807a1ddf954582dae4fc031bed2c7eb to your computer and use it in GitHub Desktop.
Save TScalzott/f807a1ddf954582dae4fc031bed2c7eb to your computer and use it in GitHub Desktop.
Log timestamped ping replies and timeouts to the screen and a logfile
<#
.DESCRIPTION
Log timestamped ping replies and timeouts to the screen and a logfile
.PARAMETER host
The host or IP to ping
.EXAMPLE
PingLog.ps1 www.google.com
#>
param (
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string[]]$hostname
)
Write-Output "Logging $hostname pings to $env:USERPROFILE\Documents\`n"
PING.EXE $hostname -t |
Select-String "(Reply|Timed)" |
ForEach-Object $_ {
"$((Get-Date).ToString('u')): $_"
} |
Tee-Object -FilePath "$env:USERPROFILE\Documents\PingLog-$((Get-Date).ToString("yyyyMMdd")).txt" -Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment