How to hide Powershell background window

I’ve changed from Windows batch files to Powershell for almost every other repeated tasks & one of the scripts that I use to connect to our IKEv2 VPN script has a shortcut on my desktop. This script helps me to connect and disconnect from the VPN network just by double clicking the shortcut. You can checkout the script here

I had multiple iterations for the script and kept on deleting and recreating the shortcut and noticed that a black window started appearing when I executed script from the shortcut.

All I could remember was, not changing any settings for the Powershell & couldn’t find a “solution” (that was mere eyesore to my rigid expectations). Interestingly, my semi desktop/server class box didn’t have this “issue”, whenever I executed the script from the shortcut, all I was provided was the “Connected” or “Disconnected” message boxes.

After sometime, I decided to check the shortcut properties on my desktop & noticed that the “Run” option was selected as “Minimized”

Powershell provides many switches & one of the switches is “WindowStyle” that supports Normal, Minimized, Maximized and Hidden styles for the Window. Well, the style “Minimized” just hid the entire window, including the message popups that had prompts.

Quickly I moved to my laptop and changed the Run to “Minimized” and that was it. No more annoying black window behind my script message boxes! No more script outputs shown on the screen. So, if you reached here seeking a how to hide those annoying black windows, give this a try.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.