I am writing a script package in PowerShell v1 that will run on schedule, let it speak once a minute. Inevitably, the time will come when the work will take more than 1 minute, and now we have two instances of the script, and then, possibly 3, etc.
I want to avoid this if the script itself checks to see if the instance itself is already there, and if so, the script exits.
I did this in other languages ββon Linux, but I never did it on Windows using PowerShell.
For example, in PHP, I can do something like:
exec("ps auxwww|grep mybatchscript.php|grep -v grep", $output);
if($output){exit;}
Is there something similar in PowerShell v1? I have never seen anything like it.
Of these common patterns that are most commonly used when running a PowerShell script?
- Lock file
- OS Task Scheduler