将$triggers += New-ScheduledTaskTrigger -AtLogOn
行添加到$triggers
数组时,我收到访问拒绝错误。
删除后,它将创建具有其他触发条件的任务而没有问题。
$TASKNAME = "Lansweeper Scan"
$TASKPATH = "Lansweeper"
$action = New-ScheduledTaskAction -Execute 'C:\Lansweeper\LsPush.exe' -Argument 'LansweeperServer'
#Set Triggers via Array
$triggers = @()
$triggers += New-ScheduledTaskTrigger -Daily -At 09:30
$triggers += New-ScheduledTaskTrigger -Daily -At 11:30
$triggers += New-ScheduledTaskTrigger -Daily -At 13:30
$triggers += New-ScheduledTaskTrigger -Daily -At 15:30
$triggers += New-ScheduledTaskTrigger -Daily -At 17:30
$triggers += New-ScheduledTaskTrigger -AtLogOn
$task = Register-ScheduledTask -TaskName $TASKNAME -Trigger $triggers -Action $action -TaskPath $TASKPATH
$task | Set-ScheduledTask