I need to use powershell script to set schedule task. The test users has an admin rights and running manually works on user’s test pc, creates the scheduled task.
However the other users doesnt have admin rights and if I send it from Intune it doesnt run. Intune only says its status is ‘failed’.
I tried to use different log on time and run level.
Here is my script (part of set task under scheduler):
**# 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."
New contributor
Akos81 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.