Start-Transcript -path C:/Script/PingLog.txt -Append
Ping.exe -t spiceworks.com | ForEach {"{0} - {1}" -f (Get-Date),$_}
Lets break this down real quick.
Ping.exe - That’s ping! powershell can use your CMD stuff just fine.
-t is as we all know, a continuous ping. can go before or after our hostname/IP address.
spiceworks.com is what we’re pinging.
Next up is a pipe (|) - We’re sending our information over to our next command.
Foreach is the next thing in our command here.
[“{0} - {1}” -f] - This is the text formatting, check the references below if you’d like to learn more
(Get-Date) - This is the date! it’s also what’s going into {0} in the text formatting above.
$_ - This is you taking your previous input from ping and putting into {1}
No comments:
Post a Comment