Problem scenario:
You have a PowerShell script that launches a pop-up window. This pop-up appears behind the PowerShell ISE GUI. Without being in the foreground, the users of this script fail to realize there is a prompt waiting for the user to take action. You want the pop-up window to be in the front. You tried things like these options to no avail:
- New-Object System.Windows.Forms.Form -Property @{TopMost = $true}
- -ArgumentList([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
- form.TopMost = “True”
- form.TopMost = $true
- form.TopMost = $True
- $form.TopLevel = $true
- set-foregroundWindow(Get-Process PowerShell).Main.WindowHandle
- $form.BringToFront()
- set-WindowsFocus
- [void]$showWindowAsync::ShowWindowAsync((Get-Process -id $pid).MainWindowHandle,
…