PowerShell script runs under a different user account when triggered by Task Scheduler

Adi Wijaya 0 Reputation points
2026-11-27T06:02:16.5933333+00:00

Hello,

I'm running into an issue where a scheduled PowerShell script appears to execute under a different user account than the service account specified in Task Scheduler.

I'm trying to understand how Task Scheduler determines the execution context and whether settings such as the task principal, logon type, or privilege elevation could explain this behavior.

Has anyone encountered something similar? What's the best way to verify the actual security context of a scheduled PowerShell process and identify why it differs from the configured account?

Thanks

Windows for business | Windows Client for IT Pros | Directory services | User logon and profiles
0 comments No comments

1 answer

Sort by: Oldest
  1. Jason Nguyen Tran 31,625 Reputation points Independent Advisor
    2026-11-27T06:47:26.7+00:00

    Hi Adi Wijaya,

    Yes, I've run into this a few times. It's usually not PowerShell itself. More often it comes down to how Task Scheduler sets up the security context for the task.

    I'd start with the task's Principal settings: which account it's set to run as, the Logon Type, and whether "Run with highest privileges" is checked. Together these decide what kind of token the task gets when it starts, so a small difference there can change who the script actually runs as.

    To see what's really happening, add a line at the top of the script that logs the current identity (for example whoami /all or [System.Security.Principal.WindowsIdentity]::GetCurrent()) to a file. Then compare that to the account configured in the task. The Task Scheduler Operational log in Event Viewer (Applications and Services Logs > Microsoft > Windows > TaskScheduler > Operational) is also worth checking. It often shows how the task was launched and which logon type was used. And if the task runs under a service account, a gMSA, or some kind of delegated credential, the effective context may not match what you'd expect at first glance.

    A couple of other things to check:

    • Does the script start any child processes? Those can end up with a different token or run under a different account.
    • Did this start after a GPO or permission change? If so, export the XML of this task and of a similar task that still works, then compare them side by side. The differences usually show up quickly.

    In my experience, the cause usually turns out to be a mismatch between the configured principal and the logon type actually used at runtime. If you check the principal settings, logon type, elevation, and the identity the script logs, you should be able to find where it goes wrong.

    Hope this helps. If it does, please mark it as the accepted answer so others with the same issue can find it.

    Jason

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.