PowerShell script won't execute as a Windows scheduled task

后端 未结 5 1358
难免孤独
难免孤独 2020-12-02 14:12

I have a PowerShell script (that works). In Windows Task Scheduler I created a new task to execute \"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\"

5条回答
  •  一生所求
    2020-12-02 15:16

    I've done this before and had similar issues. It's almost always the PowerShell security settings. Most obviously, I would double-check your execution policy (assuming that you've set it).

    Which user does the task run as? Has that user run a PowerShell script before? If I remember right, each user is prompted to "allow" PowerShell scripts to run (Y/N), when running a script for the first time (regardless of execution policy). That has bitten me before. Try:

    • logging-in as that user
    • check the execution policy
    • kick-off the script from a PowerShell prompt
    • reply to any prompts that follow.

    After the first run, you shouldn't have to worry about that again, and it should run from the task scheduler just fine.

    Depending on your domain security, you might also have to set the group execution policy. Here's an article that details how to do that, as well as a couple other things to check: PowerShell Security.

提交回复
热议问题