How to schedule a task wether the user is logged on or not in PowerShell?
Asked Answered
D

4

23

I have a problem regarding how to make a scheduled task to run whether the user is logged on or not. It must be done in PowerShell. What I have done is:

$WINDIR/system32/schtasks.exe /create /tn TaskName /sc daily /st 15:05:00 /tr "C:\cygwin\opt\IBM\tpchc\bin\tools\TheFileToRun.bat"

But can I provide an extra argument making this task run no matter if the user is logged on or off?

If it cant be done in PowerShell is it then possible to do it in another script language?

Dereliction answered 25/6, 2012 at 13:37 Comment(1)
For one, that's not powershell, that's the command line way to do it -- (see the Register-ScheduledTask cmdlet), for two, this is a duplicate of: #13966497Fandango
L
25

You'll need to specify a user (like /RU system), but it should be the default whether to run logged in or not. You can look at this link for a list of all schtasks.exe parameters.

Letterperfect answered 25/6, 2012 at 19:42 Comment(0)
M
23

if you add

/RU <username> /RP <password>

to the call to schtasks.exe you will get "Run whether user is logged on or not" selected.

You can also use the /NP instead, which will also give you "Run whether user is logged on or not", but also "Do not store password..." which will limit the accessible resources.

Mohawk answered 8/12, 2015 at 21:31 Comment(0)
O
0

I got a Working solution, just add this:

/RU "NT AUTHORITY\SYSTEM" /RP *

Will run as System and ignore password, Tested on XP

Octangle answered 28/8, 2020 at 19:54 Comment(0)
S
0

If you're using common account:

/RU {accountName} /RP {password}

If you're using gMSA account:

/RU {accountName}$ /RP 
Shinar answered 29/12, 2022 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.