Launching PowerShell Scripts Invisibly

by Jan 17, 2020

There is no a built-in way to launch a PowerShell script hidden: even if you run powershell.exe and specify -WindowStyle Hidden, the PowerShell console will still be visible for a fraction of a second.

To launch PowerShell scripts hidden, you can use a VBScript, though:

Set objShell = CreateObject("WScript.Shell")
path = WScript.Arguments(0)

command = "powershell -noprofile -windowstyle hidden -executionpolicy bypass -file """ & path & """"

objShell.Run command,0

Save this as test.vbs, and make sure you save it with ANSI encoding (use Notepad and choose the encoding in the bottom dropdown list in the SaveAs dialog). VBScript cannot handle scripts saved in UTF8 encoding. When you try and run such a script, you get an exception complaining about invalid characters.

To launch a PowerShell script invisibly, this is the command to run:

Note that while wscript.exe is hiding the PowerShell console window, any WPF window you are opening, i.e. by using Out-GridView, will continue to work and display as before.

Wscript.exe c:\pathtovbs.vbs c:\pathtoPS1file.ps1

You are a PowerShell Professional, passionate about improving your code and skills? You take security seriously and are always looking for the latest advice and guidance to make your code more secure and faster? You’d love to connect to the vibrant PowerShell community and get in touch with other PowerShell Professionals to share tricks and experience? Then PowerShell Conference EU 2020 might be just the right place for you: (June 2-5, 2020 in Hanover, Germany).

It’s a unique mixture of classic conference with three parallel tracks filled with fast-paced PowerShell presentations, and advanced learning class with live discussions, Q&A and plenty of networking.

Secure your seat while they last: Help build the agenda and make this “your” event by submitting hypothetical sessions you’d like to hear: And if you’d like to present yourself and join the speakers’ team, submit proposals:

Twitter This Tip! ReTweet this Tip!