Skip to content

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

License

Notifications You must be signed in to change notification settings

gbuktenica/PsRun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published