Add-Type -AssemblyName "PresentationCore", "PresentationFramework", "WindowsBase" [xml]$xamlMarkup = @' '@ $xamlGui = [System.Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xamlMarkup)) $xamlMarkup.SelectNodes('//*[@Name]') | ForEach-Object { if ($_.Name.Contains("ToggleButton")) { $ToggleBtn = $xamlGui.FindName($_.Name) [Void]$ToggleButtons.Add($ToggleBtn) } else { New-Variable -Name $_.Name -Value $xamlGui.FindName($_.Name) } } #region Script Functions function Hide-Console { <# .SYNOPSIS Hide Powershell console before show WPF GUI. #> [CmdletBinding()] param () Add-Type -Name Window -Namespace Console -MemberDefinition ' [DllImport("Kernel32.dll")] public static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow); ' [Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0) } #endregion #region Controls Events $xamlGui.add_MouseLeftButtonDown( { $xamlGui.DragMove() }) $MinimizeButton.add_MouseLeftButtonDown( { $xamlGui.WindowState = "Minimized" }) $CloseButton.add_MouseLeftButtonDown( { $xamlGui.Close() }) #endregion Hide-Console $xamlGui.ShowDialog() | Out-Null