Show-PowerShell / Hide-PowerShell

  • Comments 7

During the Week of WPF, someone requested an example of how to minimize the PowerShell window.

Here's a quick module to make it happen.  Copy/paste the code below into Documents\WindowsPowerShell\Packages\PowerShell\PowerShell.psm1

$script:showWindowAsync = Add-Type –memberDefinition @”
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThru

function Show-PowerShell() {
     $null = $showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 10)

function Hide-PowerShell() {
    $null = $showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 2)

Now you can use the code below to Show and Hide PowerShell:

Add-Module PowerShell
# Minimize PowerShell
sleep 2
# Then Restore it

Hope this Helps,
James Brundage[MSFT]

Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post
  • Yes, It works but only when you launch the shortcut to Windows PowerShell V2 (CTP2) previously. If you first type cmd.exe and then you type:

    powershell.exe script.ps1 you have 2 different pids (one for cmd.exe and one for powershell.exe)

    It would be great that we can hide completely the powershell console window (not minimize) while the script is executing :)

  • I know this isn't the WPF way of doing things, but I wanted this functionality early on with Powershell v1 after having been spoiled by Quake-style terminals like Yakuake. I stumbled across AutoHotkey ( which basically allows you to create mini scripts and map them to user-specified key combinations.

    The following AutoHotkey script shows/hides a console with a WindowsKey+` combination, although you can tweak it to whatever combination you want. If a console is not already running when the key combination is struck, a new Powershell window is launched:


    DetectHiddenWindows, on

    IfWinExist ahk_class ConsoleWindowClass


    IfWinActive ahk_class ConsoleWindowClass


    WinHide ahk_class ConsoleWindowClass

    WinActivate ahk_class Shell_TrayWnd




       WinShow ahk_class ConsoleWindowClass

       WinActivate ahk_class ConsoleWindowClass




    Run C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

    DetectHiddenWindows, off


    Works a treat!

  • Check this out maybe:

    Uses VBScript to hide the PowerShell window.

  • Thanks for the info. Interesting workaround when we need to run powershell commands in background but it doesn´t work when we need to show windows forms :(

  • Thanks for the AutoHotkey script. It works great!

  • It also work with windows forms but you need launcher

  • This is an awesome script, but note the pretty quote marks ” ... “ and em-dashes – are not safe to copy and paste directly into a script.

Page 1 of 1 (7 items)

Show-PowerShell / Hide-PowerShell