Reputation: 13
I am new to powershell but I am trying to learn. Right now, I need to set a scheduled script to run every 10 minutes and ping on of our servers while saving that information to a log file. I have a script that does this but the issue I am facing is with the log.txt
Every time the script runs it overwrites the log file. My questions is: how can I tell powershell to update the log file and not overwrite the contents of it when it is run?
My script: Ping.exe <HOSTNAME> | ForEach {"{0} - {1}" -f (Get-Date),$_} > D:\ping.txt
Upvotes: 0
Views: 537
Reputation: 628
I believe > D:\ping.txt
is telling Powershell to overwrite your log file. Have you tried >> D:\ping.txt
instead?
EDIT: For future reference, Microsoft can explain this better than I can: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-7.1#powershell-redirection-operators
Upvotes: 1