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

后端 未结 6 1507
小蘑菇
小蘑菇 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:08

    If the script was launched using the powershell.exe -File switch, you can detect all powershell instances that have the script name present in the process commandline property:

    Get-WmiObject Win32_Process -Filter "Name='powershell.exe' AND CommandLine LIKE '%script.ps1%'"
    

提交回复
热议问题