CodexBloom - Programming Q&A Platform

PowerShell script doesn't execute scheduled task when using RunAs with different user

šŸ‘€ Views: 33 šŸ’¬ Answers: 1 šŸ“… Created: 2025-06-03
powershell task-scheduler scripting PowerShell

Could someone explain I'm working through a tutorial and I'm having trouble with I'm sure I'm missing something obvious here, but I'm working on a project and hit a roadblock. I'm trying to schedule a PowerShell script to run automatically using Windows Task Scheduler, but I encounter issues when I specify a different user in the 'Run with highest privileges' option. The task runs successfully when I log in as the administrator account, but it fails when it tries to run under the specified user account. I see the following behavior in the history: 'Task Scheduler failed to start instance 0 of task...'. I've confirmed that the user has the necessary permissions to run PowerShell and execute the script. Here's the command I’m trying to run in my PowerShell script: ```powershell Get-Process | Where-Object { $_.CPU -gt 100 } | Export-Csv "C:\temp\high_cpu_processes.csv" -NoTypeInformation ``` I've also tried running the script manually under that user account, and it works without any issues. I ensured that the execution policy is set appropriately with `Set-ExecutionPolicy RemoteSigned`. Additionally, I checked the security settings of the script file and the task itself to ensure that the user has both Read and Execute permissions. Could this be related to the User Account Control (UAC) settings? Or is there something else I might be missing when configuring the scheduled task? Any insights would be greatly appreciated. I'd really appreciate any guidance on this. I'm working on a web app that needs to handle this. I'm using Powershell latest in this project. What am I doing wrong? Any feedback is welcome! For context: I'm using Powershell on Ubuntu 22.04. Thanks for taking the time to read this!