I have a powershell script I want to use to monitor the size of a file (at a certain interval) and send me an email alert if the file reaches a certain size. However, after it discovers that the file has reached that size, the powershell script exits.
Presently the script operates in a for loop, with the file-size check happening first, and if it hasn't passed the maximum size, it will wait for the given time-interval and check the file size again. But I'm thinking about changing this for loop to a do...while so that it waits the interval of time first and then checks the size of the file.
But the script will still exit when the email is sent.
Is there any way to ensure that the script will be re-run when it exits after the email is sent?
I read that there are processes in database systems that monitor other processes to make sure that they are running, and if they are not, the watching process re-spawns the process that died.