Assure only 1 instance of PowerShell Script is Running at any given Time

后端 未结 6 1452
小蘑菇
小蘑菇 2021-01-17 12:31

I am writing a batch script in PowerShell v1 that will get scheduled to run let\'s say once every minute. Inevitably, there will come a time when the job needs more than 1 m

6条回答
  •  北海茫月
    2021-01-17 13:25

    It's "always" best to let the "highest process" handle such situations. The process should check this before it runs the second instance. So my advise is to use Task Scheduler to do the job for you. This will also eliminate possible problems with permissions(saving a file without having permissions), and it will keep your script clean.

    When configuring the task in Task Scheduler, you have an option under Settings:

    If the task is already running, then the following rule applies: 
    Do not start a new instace
    

提交回复
热议问题