Powershell:将-Atlogon计划的作业触发器添加到触发器数组

时间:2018-07-05 10:18:55

标签: powershell

$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

0 个答案:

没有答案