首页 > 代码库 > 显示、隐藏 PowerShell

显示、隐藏 PowerShell

以下是一个快速实现该需求的 module。只要将以下代码复制粘贴到 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)}

现在,您可以用这段代码来显示或隐藏 PowerShell:

Add-Module PowerShell# Minimize PowerShellHide-PowerShellsleep 2# Then Restore itShow-PowerShell

from:http://blog.vichamp.com/powershell/2014/06/23/show-powershell-hide-powershell/

    http://technet.microsoft.com/zh-cn/magazine/ms633548.aspx