Powershell script not running on scheduled task

后端 未结 2 656
再見小時候
再見小時候 2021-01-27 03:34

I can run the script outside and inside the Task Scheduler. But the scheduled tasks will not run the script automatically when triggered. I have tried configuring the Local Secu

相关标签:
2条回答
  • 2021-01-27 03:56

    Ensure you have your execution to unrestricted.

    Set-ExecutionPolicy Unrestricted 
    

    And add the following action into the Program\Script section and click Yes on the prompt that appears.

    PowerShell.exe "& 'C:\LocationFolder\YourScript.ps1'" 
    

    If you can not set your execution policy to unrestricted just add -NoProfile -ExecutionPolicy Bypass to the above command.

    0 讨论(0)
  • 2021-01-27 04:18

    Call the Powershell.exe in your schedulded task:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    

    Set this arguments:

    -noprofile -executionpolicy unrestricted -noninteractive -file "C:\Path\To\MyScript.ps1"
    
    0 讨论(0)
提交回复
热议问题