How to set schedule.service "Run whether user is logged on or not" in Powershell?
Asked Answered
J

1

3

I need to create a schedule task using Powershell with "Run whether user is logged on or not".

I use the following codes to create a task, and I've checked the members of settings, principal, triggers, and action, but failed to find the setting I need.

$service = new-object -com("Schedule.Service")
$service.connect($servername)
$rootFolder = $service.Getfolder("\")
$taskDefinition = $service.NewTask(0) 
$settings = $taskDefinition.Settings
$principal =  $taskDefinition.Principal
$triggers = $taskDefinition.Triggers
$Action = $taskDefinition.Actions.Create( 0)
$rootFolder.RegisterTaskDefinition( $taksName, $taskDefinition, 6, $taskRunAsuser , $taskRunasUserPwd , 0)

Does anyone know how to do that?

Thanks

Jacklyn answered 7/10, 2012 at 15:49 Comment(0)
J
3

It was the last parameter in the RegisterTaskDefinition() method... change it from 0 to 1.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa382577(v=vs.85).aspx

Jacklyn answered 7/10, 2012 at 23:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.