Show-PowerShell / Hide-PowerShell

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 @”
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThrufunction 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
Hide-PowerShell
sleep 2
# Then Restore it
Show-PowerShell
Hope this Helps,
James Brundage[MSFT]
Author

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.
0 comments
Discussion is closed.