u/leuit

I wanted to run scripts in the logged-on user’s security context, so I built a PowerShell module

I wanted to run scripts in the logged-on user’s security context, so I built a PowerShell module

I kept running into situations where a fix needed to happen in a logged-on user session (HKCU, Explorer, user-installed apps, notifications, browser settings, Outlook auth, etc.), but most automation tools execute as NT AUTHORITY\SYSTEM or require the user’s password.

Existing approaches definitely exist, and some are quite clever, but I kept running into tradeoffs that didn’t fit what I wanted:

  • Asking for the user’s password
  • Interrupting the user session
  • Scheduled task workarounds
  • Poor targeting in terminal server / multi-session environments
  • Remoting-style object serialization limitations when passing data back and forth

So I built PSUserContext: a binary PowerShell module for running scripts in another user's interactive session and security context.

Some scenarios where this has been useful:

  • Restarting user processes (explorer.exe, Teams, browsers)
  • User profile remediation
  • Outlook profile/config fixes
  • User-scoped app troubleshooting

A few design goals:

  • Execute from SYSTEM / RMM contexts
  • Run inside an existing logged-on user session
  • No user password required
  • No session takeover or interruption
  • Better object handling than traditional remoting serialization

GitHub:
https://github.com/walliba/PSUserContext

Still actively evolving, so I’d appreciate feedback, criticism, weird edge cases, or “why didn’t you just do X?” from people who’ve solved similar problems.

u/leuit — 9 hours ago