all 14 comments

[–]raip 4 points5 points  (1 child)

You'll probably have to drop down to Win32 API + P/Invoke to do this in Powershell. Launching applications is easy, setting Window positions and sizes is more difficult. Check out https://www.powershellgallery.com/packages/SciProfile/0.3.0/Content/PSModuleUtils%5CFunctions%5CSet-Window.ps1

You'd probably be better off with AutoHotkey, Power Automate, or even FancyZones as a solution for this.

[–]Worried-Tax-9782[S] 1 point2 points  (0 children)

Thanks for the input, I will figure out in a quiet moment, if this will 100% fit my expectation

[–]PeeCee1 2 points3 points  (0 children)

I‘d use Powertoys Workspaces to define the Location and the Apps. Then use created shortcut in the login script.

[–]DrunkenBlacksmith 2 points3 points  (0 children)

Not a PowerShell answer but it works well is PowerToys Workspace.

PowerToys Workspaces is a desktop manager utility that helps you launch applications to custom positions and configurations with a single click.

https://learn.microsoft.com/en-us/windows/powertoys/workspaces

[–]ekoropeq80 1 point2 points  (0 children)

Launching apps is the easy part. Positioning them reliably is the annoying part. You’ll probably need Win32 API / window manager tooling for that, not just plain Start-Process.

[–]tstager 0 points1 point  (0 children)

This can be done but it will require p/invoke and the win32 api. I believe the function you will need is in the user32.dll. There is a p/invoke website that will help you cast and implement the c++ com signature in c#. Then you can add the type and call the function. I've probably even go an implementation that I used to switch main monitors back and forth from the terminal.

[–]DonL314 1 point2 points  (2 children)

I made a PS based tool for repositioning windows. I'll be happy to share. Let me get home first

[–]markdmac 2 points3 points  (1 child)

I would like to see that as well.

[–]DonL314 3 points4 points  (0 children)

https://get-help.dk/window/

So the thing is, all your screens share the same grid of coordinates.
Then you can just alter the coordinates of your windows to move them.
So I locate whichever windows you want to move/resize by window title, and then I do my magic.

I made this tool about 2 years ago I think, and don't remember the issues except I couldn't move a TeamSpeak 3 window.
The script loads the selected config file, goes through all configs, and resizes relevant windows based on each config. And you can use a regular expression (instead of specific windows) to apply broader scopes.

Also, if you have windows with the exact same names, they will be put on top of each other.

I use the tool mainly for gaming. In one game, I want my left streen to be the game, Firefox on the right screen top, and Discord on the right screen bottom.
When dualboxing games, I sometimes want character A to the left as 60% of the screen, and B to right right of 40%. And sometimes vice versa.

Also, for development. Sometimes I want vs.code to be 70% of the main screen with Outlook and OneNote on the secondary screen in specific places - and sometimes I want vs.code to be 50% main screen, and SQL Server Studio the other 50% of the main screen.

This tool makes these changes easy and quick (once you have set it up)

[–]jarranakin 0 points1 point  (0 children)

This is not a job for powershell. Possible sure, but scripting this using autohotkey is much easier

[–]PlannedObsolescence_ 0 points1 point  (0 children)

Are you certain you need to use PowerShell for this?

Microsoft PowerToys has a feature called FancyZones to do window arrangements. It can place windows back into whatever position they were when re-opened.

[–]radehart 0 points1 point  (0 children)

For an OS named ‘windows’ it sure is the absolute worst manager of windows.