Run Powershell as Scheduled Task

AintGotNoTime 161 Reputation points
2021-10-06T13:49:51.623+00:00

I am trying to run a PowerShell script as a scheduled task but it seems not to work. I have tried man different suggestions but none have worked. It starts, says it launches powershell, launches the script and then completes the action. But the problem is that it never sends an email that it completed. If I run the script manually it runs just fine and sends out the email. The following are my settings. I have tried quotes around the add arguments but still does not run, at this point I am rather confused, why it runs but does nothing.

General Settings
run is user is logged on or not
Checkbox for do not store password
configure for Win 2012 r2

Triggers
Run every Monday

Actions
Start a program
Program/script = Powershell.exe

add arguments = -ExecutionPolicy bypass -file 'D:\Apps\OnboardMailboxesV3.5.ps1'
Start in = d:\apps\

Conditions and settings are just default

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-10-06T20:19:27.847+00:00

    if you're using "Run whether user is logged in or not", then you should NOT tick the "Do not store password" checkbox. Otherwise, how is it going to use your account to access network resources, without using the password?

    Also, try changing the setting to "Run only when user is logged in" and just set a time trigger to make the schedule task run by itself. See if that works or not.

    Lastly, try running a very simple Powershell script instead of the one you're trying to run. In your test Powershell script, just do something like:

    write-host "test"

    and just add a -noexit to your scheduled task arguments (under Actions). What should happen is that your schedule task will run and will leave the Powershell window open, which then allows you to verify whether the script has output the word "test" or not. Try this with both "Run only when user is logged in" and "Run whether user is logged in or not".

    If both are working fine, then the issue is not with scheduled task and it'll be an issue with your actual script.


2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2021-10-06T14:16:40.96+00:00

    Under what user account is the scheduled job run? Does the account have permission to access the network (which is necessary to send e-mail!)?


  2. Rich Matheisen 47,901 Reputation points
    2021-10-06T18:27:01.463+00:00

    When you said "Checkbox for do not store password" did you mean you DID check that box? Did you notice it also says "The task will only have access to local computer resources"? Access to the network isn't a LOCAL resource.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.