CodexBloom - Programming Q&A Platform

PowerShell 7.3 - implementing Scheduled Tasks scenarios to Run with Custom User Credentials

šŸ‘€ Views: 92 šŸ’¬ Answers: 1 šŸ“… Created: 2025-06-11
powershell scheduled-tasks authentication PowerShell

Hey everyone, I'm running into an issue that's driving me crazy. I recently switched to I've been researching this but I'm working with a frustrating scenario when trying to create a scheduled task in PowerShell 7.3 that runs a script under a specific user account..... I've set up the task using `New-ScheduledTask` and specified the user credentials, but when I run the task, it fails with the behavior `0x8007052E - Logon failure: unknown user name or bad password.` I've double-checked the credentials and they are correct. Here's the code I'm using to create the scheduled task: ```powershell $action = New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument '-File C:\Scripts\MyScript.ps1' $trigger = New-ScheduledTaskTrigger -AtStartup $credential = Get-Credential 'mydomain\myuser' Register-ScheduledTask -Action $action -Trigger $trigger -User $credential.UserName -Password $credential.GetNetworkCredential().Password -TaskName 'MyPowerShellTask' -Description 'Runs my script at startup' ``` Despite providing the correct username and password, the task fails to run. I've also tried setting the `-RunLevel` parameter to `Highest` but it didn't help. I have permissions to create tasks and the user account has permission to log on as a batch job. When I check the Task Scheduler logs, I see entries indicating that the task was triggered but failed to start due to authentication issues. Is there a specific configuration I’m missing or a known scenario with PowerShell 7.3 that could cause this behavior? Any insights or suggestions would be greatly appreciated! Has anyone else encountered this? Is there a better approach? Am I approaching this the right way? I'm on Debian using the latest version of Powershell. Any suggestions would be helpful. I'd love to hear your thoughts on this.