Powershell:在 Intune 的任务计划程序下设置新任务

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

我需要使用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."
powershell windows-task-scheduler intune
1个回答
0
投票

删除 -atlogon 位。为此,您需要管理员权限。使用其他触发器。就像每 4 小时一次。

© www.soinside.com 2019 - 2024. All rights reserved.