views:

936

answers:

2

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)

+1  A: 

I think you would need to use "nt authority\localservice" as the user name.

Kindness,

Dan

Daniel Elliott
+2  A: 

This code snippet will use the PowerShellPack's Task Scheduler module to schedule a task to run as SYSTEM immediately:

New-Task |
    ForEach-Object {
        $_.Principal.Id = "NTAuthority\SYSTEM"
        $_.Principal.RunLevel = 1
        $_
    } |
    Add-TaskAction -Script {
        "SystemTask" > C:\myTest.txt
    } |
    Add-TaskTrigger -OnRegistration |
    Register-ScheduledTask SystemTask
Start-Automating
Thanks Media. I'll check this out tomorrow.
devlife