我需要使用powershell脚本来设置计划任务。测试用户具有管理员权限,并在用户的测试电脑上手动运行,创建计划任务。 但是其他用户没有管理员权限,如果我从 Intune 发送它,它就不会运行。 Intune 仅表示其状态为“失败”。
我尝试使用不同的登录时间和运行级别。 这是我的脚本(调度程序下设置任务的一部分):
**# Define the action for the scheduled task**
$taskAction = New-ScheduledTaskAction -Execute "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -Argument '-ExecutionPolicy Bypass -File "C:\\Temp\\appremove.ps1"'
**# Define the trigger to run the task at logon for any user**
$taskTrigger = New-ScheduledTaskTrigger -AtLogOn
$taskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
*New-ScheduledTaskPrincipal -UserId $currentUser -LogonType Interactive -RunLevel Limited*
**# Register the scheduled task**
Register-ScheduledTask -Action $taskAction -Trigger $taskTrigger -TaskName $taskName -User $currentUser -Settings $taskSettings
**# Display a confirmation message**
Write-Host "Scheduled task has been created to run '$scriptPath' at every logon for any user."
删除 -atlogon 位。为此,您需要管理员权限。使用其他触发器。就像每 4 小时一次。