Stop script if it ran within last hour

Thanks to the community I got a script working that pings a list of servers every 10 minutes via Task Scheduler. If a server(s) go down I get an email and text message.


I would like to get the initial email/text, but if we know it’s down I don’t want to get notified every 10 minutes. I’d like to get the initial notification then if it’s still down after an hour get another notification. How can I block the notifications in that 50 minute time frame every hour?

You could update the results of each trigger in a CSV with the timestamp and for the servers not reachable, check the timestamp before sending the mail and update the timestamp.

Thanks for the suggestion. I’m having an issue writing the date/time to the CSV file. I thought I could use this format for date/time, but when I look in the CSV it just displays the number of characters, not the actual date and time. How can I compare the current time with the last entry in the CSV?

get-date -Uformat "%Y%m%d%H%M%S" | Export-Csv -Path .\serverstatus.csv -NoTypeInformation -NoClobber -append -force

export-csv is an ‘odd duck’. If you really want to export to a csv file, you can just do out-file.


get-date -Uformat "%Y%m%d%H%M%S" | out-file .\serverstatus3.csv -append -force

Thanks. I ended up using

Test-Path -Path $LogFile -NewerThan $NewDate.AddMinutes(-55) to test the age of the CSV file.