Run a powershell script in the background once per minute

后端 未结 8 2191
攒了一身酷
攒了一身酷 2020-12-23 16:38

I want a powershell script to be run once per minute in the background. No window may appear. How do I do it?

8条回答
  •  星月不相逢
    2020-12-23 17:44

    To create a background powershell task to run a script that repeats every minute with no visible window at all, run powershell as administrator and then use the Register-ScheduledJob cmdlet to run your script. Here's an example of how to make that happen:

    Register-ScheduledJob -Name 'SomeJobName' -FilePath 'path\to\your\ps1' -Trigger (New-JobTrigger -Once -At "9/28/2018 0am" -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration ([TimeSpan]::MaxValue))
    

    If you want to manually force this job to run (perhaps for troubleshooting purposes) you can use the Get-ScheduledJob cmdlet like this:

    (Get-ScheduledJob -Name 'SomeJobName').StartJob()
    

提交回复
热议问题