Powershell - Create Scheduled Task to run as local system / service

前端 未结 3 1890
生来不讨喜
生来不讨喜 2021-02-07 10:33

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.

3条回答
  •  Happy的楠姐
    2021-02-07 11:08

    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
    

提交回复
热议问题