运行此计划任务时遇到问题

问题描述 投票:0回答:1

我有这个脚本创建了计划任务以每周重新启动计算机。任务创建成功,但不会在指定时间自动运行。

# Create task action
$taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument 'Restart-Computer - Force'
# Create a trigger (Thursday at 9:00 AM)
$taskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Thursday -At 9:00am
# The user to run the task
$taskUser = New-ScheduledTaskPrincipal -UserId "LOCALSERVICE" -LogonType ServiceAccount
# The name of the scheduled task.
$taskName = "Weekly Reboot"
# Describe the scheduled task.
$description = "Forcibly reboot the computer at 9:00am on Thursday"
# Register the scheduled task
Register-ScheduledTask -TaskName $taskName -Action $taskAction -Trigger $taskTrigger -Principal     $taskUser -Description $description
$shellObject = New-Object -ComObject Wscript.Shell
$notification = $shellObject.Popup("Computer will reboot in 30 minutes",0,"Reboot Notification")`

任务部署成功,可以在任务计划程序中看到,但不会自动运行。

windows powershell windows-task-scheduler taskscheduler
1个回答
0
投票

与其他用户一起尝试:

-UserId "NT AUTHORITY\SYSTEM"
© www.soinside.com 2019 - 2024. All rights reserved.