PowerShell – Focus this Window or Process

email me

 $WindowState = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
    add-type -name win -member $WindowState -namespace native
    [native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0)    
    SetForegroundWindow(this.Handle)

 

Notes

$form.TopMost = $True # force window to stay on top