Can anyone tell me how to create a scheduled task using powershell that runs as the local system or local service?
Everything works great except the call to ITaskFolder.RegisterTaskDefinition().
If I pass in $null, or "", than the call bombs saying invalid username or password. Any thoughts"
$Rootfolder.RegisterTaskDefinition("Test", $Taskdef, 6, "LOCAL SERVICE", "", 3)
I think you would need to use "nt authority\localservice" as the user name.
Kindness,
Dan
This code snippet will use the PowerShellPack's Task Scheduler module to schedule a task to run as SYSTEM immediately:
For those who can use PowerShell 3.0 on Windows 8 or Windows Server 2012, new cmdlets will let you do it in a simple way when registering your scheduled task with the cmdlet
Register-ScheduledTask
and as argument-User "System"
Here is a scheduled task created entirely with PS, its purpose is to restart a service My Service, using the SYSTEM account, 3 minutes after the system has started:
NB: you will need to run powershell as an administrator for that script.