I am trying to get/set the current window position, relative to my screens (x,y) coordinates, within a powershell script (running in that window). In other words, I would like my powershell script ran in one (window) to move itself to a fixed position I decide. (Unfortunately windows insists on changing the location of where the shell window is opened, every time it is run.)
In powershell, setting the size is trivial via the following:
[console]::BufferHeight=9001
[console]::BufferWidth=140
[console]::WindowHeight=50
[console]::WindowWidth=140
So I was expecting to be able to use something like this:
[console]::SetWindowPosition(100,100)
# <error output>
# MethodInvocationException: Exception calling "SetWindowPosition" with "2" argument(s):
# "The window position must be set such that the current window size fits within the
# console's buffer, and the numbers must not be negative. (Parameter 'left')
# Actual value was 100."
Also, tried checking with: (Get-Host).UI.RawUI | Select-Object *
, but found nothing useful there.
Q: What is the most simple in-code powershell commands to set/move the current window?
Unhelpful & outdated Answers & References:
- Controlling window position of a Powershell console
- PowerShell, Windows Terminal size and position manipulation
- What is the best way to move the powershell console window to the left side of the screen?
- MS Windows API
These look more promising: