/PsRun

Run a PowerShell script in the user context without a script window

Primary LanguageVBScriptMIT LicenseMIT

PsRun

License Copyright Glen Buktenica PowerShell 5 PowerShell 6 PowerShell 7
Running PowerShell scripts in a user context without any window being displayed at all is not possible just using PowerShell.
The closest way is the WindowStyle hidden switch available from PowerShell version 2 onwards:

# PowerShell 2 to 5.1
powershell.exe -WindowStyle hidden -File Run-Script.ps1
# PowerShell 6 to 7
pwsh.exe -WindowStyle hidden -File Run-Script.ps1

This will still display a temporary PowerShell window.

Pop Up

To completely remove the window from the use context use this vbs to call the PowerShell script:

wscript.exe PsRun.vbs Run-Script.ps1

The most common use case for this operation is a scheduled task that needs to run in the user context and needs to not display an annoying pop-up.

Task Properties