'Maximize window and bring it in front with powershell

Is there a way to bring a window in front from powershell? I tried this to hide all windows (working) and bring me the powershell back (not working)

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$shell = New-Object -ComObject “Shell.Application”
$shell.MinimizeAll()

$a = Get-Process | Where-Object {$_.Name -like "powershell"}
[Microsoft.VisualBasic.Interaction]::AppActivate($a.ID)

Any suggestions?



Solution 1:[1]

This is cheating a bit since it's using WScript, but the following one-liner places the window in the foreground without requiring any external cmdlet installation.

In the example below, "notepad" is the process name associated with the window.

Credit goes to the Idera forum posting here by JSanders:

(New-Object -ComObject WScript.Shell).AppActivate((get-process notepad).MainWindowTitle)

Solution 2:[2]

Wscript one liner is working for me when I replace .MainWindowTitle to .Description at the end. So the line becomes:

(New-Object -ComObject WScript.Shell).AppActivate((get-process notepad).Description)

Yet to find a similar one liner for maximizing it...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott Dudley
Solution 2 Upo001