Hide PowerShell Console from a GUI

PowerShell is a very powerfull scripting language that allows you to build many useful tools using command lines.

For a better interactivity, it’s also possible to build a graphical user interface (GUI) allowing to pilot these tools.

By default, when a PowerShell script containing a GUI is run, the user interface is displayed of course, but the console too !

The following script block allows to hide the PowerShell console:

# Hide PowerShell Console
Add-Type -Name Window -Namespace Console -MemberDefinition '
public static extern IntPtr GetConsoleWindow();
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
$consolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consolePtr, 0)