Maximizing a (Chrome) Window with PowerShell

(Actually, don't do any of this, just use WIN-SHIFT-Arrow key to shove the window to an edge, where you can interact with it again).

Scenario and background

One of my windows opened off screen and I my go-to ALT-SPACE-X did not solve my issue. I also googled and found a number of Stack Overflow answers, but they didn't quite do what I want.

I know enough PowerShell to cause damage, I have years of C# experience and I've dabbled with the Windows API (for play projects) more than once.


Solution

1. Add POWER through .NET and the Windows API

Add-Type "using System; using System.Runtime.InteropServices; public class Window { [DllImport(""user32.dll"")] public extern static bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw); }"

2. Use PowerShell to find all processes, passing each process' main window handle to our Windows API

Get-Process chrome | ForEach-Object { [Window]::MoveWindow($_.MainWindowHandle, 100, 100, 1024, 768, $true) }

3. Pat yourself on your back - you're done!


Was anything in the above confusing? Did it work/not work for you? Add your comments below! 😉

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints