PowerShell/CMD – Ping Methods and Logging with Timestamps

Various ways to ping…

Powershell with a timestamp and output to file (can be an easy one-liner):

$ipaddress = ""
$dnsflag = "-a"
$timestamp = Get-Date -f yyyyMMdd_HHmmss
$outputfile = "$($env:USERPROFILE)\Desktop\Ping - $ipaddress - $timestamp.txt"

$host.ui.RawUI.WindowTitle = "Pinging $ipaddress" ; ping -t $dnsflag $ipaddress 2>&1 |Foreach{'{0} - {1}' -f (Get-Date -f yyyyMMdd_HHmmss),$_} | select -skip 1 | Tee-Object "$outputfile"


Command Prompt one-liner to log to file with timestamp:

title Pinging &ping -a -t|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo( !date! !time! !data! ) && echo !date! !time! !data! >> "C:\Users\Mathew\Desktop\Logging-Output\Ping -2019-12-08_230103_172.16.0.1.txt"&ping -n 2 localhost>nul"


Leave a Reply

Your email address will not be published. Required fields are marked *