Powershell script to snap an app in Windows 8

You can not, from inside a Windows 8 application, snap it.

That doesn’t mean there is no other way :)

At work, we have to test our app in a snapped state, so we need a way to programmatically make it happen. We discovered that there are two keyboard shortcuts for this action. Windows Key + . (the period key) snaps to the right edge, and Windows Key + Shift + . snaps to the left edge.

So all we have to do is send these keys to the operating system. Sending the Windows Key is tricky, and not supported using only [System.Windows.Forms.SendKeys]::SendWait.

So here’s an alternative:

Download InputSimulator.dll

Run the following commands on a Powershell prompt:

[WindowsInput.InputSimulator]::SimulateModifiedKeyStroke('LWIN', 'OEM_PERIOD')

And your app will snap to the right edge. I am still researching how to snap to the left edge, it’s a more complicated call to SimulateModifiedKeyStroke, but will keep researching.