Run a powershell script in the background once per minute

后端 未结 8 2029
攒了一身酷
攒了一身酷 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:32

    On the [General] tab in the Task Scheduler properties for the task, selecting the "Run whether user is logged on or not" radio button prevents the window from appearing on my Windows 7 machine.

    0 讨论(0)
  • 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()
    
    0 讨论(0)
提交回复
热议问题