Powershell script does not run via Scheduled Tasks

后端 未结 18 754
南方客
南方客 2020-12-02 23:12

I have a small script on my Domain Controller that is setup to email me via SMTP about the latest Security Event 4740.

The script, when executed manually, will run a

相关标签:
18条回答
  • 2020-12-02 23:23

    Change your Action to:

    powershell -noprofile -executionpolicy bypass -file C:\path\event4740.ps1

    On a Windows 2008 server R2: In Task Scheduler under the General Tab - Make sure the 'Run As' user is set to an account with the right permissions it takes to execute the script.

    Also, I believe you have the "Run only when user is logged on" Option checked off. Change that to "Run whether user is logged on or not". Leave the Do Not Store password option unchecked, and you'll probably need the "Run with Highest Privileges" option marked.

    0 讨论(0)
  • 2020-12-02 23:23

    I had the same issue, while running the couple of scripts. When i execute it manually from task scheduler, The script was executing flawlessly. But it was not executing at the scheduled time automatically.

    The following resolution worked for me

    Find the location of the powershell exe , Right click and go to security options,Add the "Authenticated users" to the group or user names and give full control.

    Once this is done wait for the script to executed.

    0 讨论(0)
  • 2020-12-02 23:25

    I had very similar issue, i was keeping the VSC window with powershell script all the time when running the schedule task manually. Just closed it and it started working as expected.

    0 讨论(0)
  • 2020-12-02 23:25

    If youu are having this problem under WIN 10 this might solve your problem as it did for me. An update messed up the task scheduler.

    http://answers.microsoft.com/en-us/windows/forum/windows_10-performance/anniversary-update-version-1607-build14393-breaks/d034ab52-5d49-4b92-976a-a1355b5a6e6d?page=2

    This comment solved my problem.

    Your tip about "one-time" tasks works great - it will definitely be sufficient as a workaround until MS fixes the issue. The only advantage to "daily" as far as I can see is that lack of the arbitrary date associated with the run time. It might be confusing to others as to why the job is set to start on X date.

    Trigger settings "Einmal" means "one-time", "Sofort" means "At once"

    0 讨论(0)
  • 2020-12-02 23:25

    In my case it was related to a .ps1 referral inside the ps1 script which was not signed (you need to unblock it at the file properties) , also I added as first line:

    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force

    Then it worked

    0 讨论(0)
  • 2020-12-02 23:27

    Although you may have already found a resolution to your issue, I'm still going to post this note to benefit someone else. I ran into a similar issue. I basically used a different domain account to test and compare. The task ran just fine with "Run whether user is logged on or not" checked.

    A couple of things to keep in mind and make sure of:

    1. The account being use to execute task must have "Logon as batch job" rights under the local security policy of the server (or be member of local Admin group). You must specified the account you need to run scripts/bat files.
    2. Make sure you are entering the correct password characters
    3. Tasks in 2008 R2 don't run interactively specially if you run them as "Run whether user is logged on or not". This will likely fail specially if on the script you are looking for any objects\resource specific to a user-profile when the task was created as the powershell session will need that info to start, otherwise it will start and immediately end. As an example for defining $Path when running script as "Run whether user is logged on or not" and I specify a mapped drive. It would look for that drive when the task kicks off, but since the user account validated to run task is not logged in and on the script you are referring back to a source\object that it needs to work against it is not present task will just terminate. mapped drive (\server\share) x:\ vs. Actual UNC path \server\share
    4. Review your steps, script, arguments. Sometimes the smallest piece can make a big difference even if you have done this process many times. I have missed several times a character when entering the password or a semi-colon sometimes when building script or task.

    Check this link and hopefully you or someone else can benefit from this info: https://technet.microsoft.com/en-us/library/cc722152.aspx

    0 讨论(0)
提交回复
热议问题