I need to be able to run this script and have it maximize a window if it isn't already maximized. And restore the window if it isn't. The window is just whatever is currently active so no need to get specifi开发者_开发知识库c (but bonus points if you do) 8O)
I plan on activating it from a short-cut keystroke.
It does need to run under PS v1 (I know, I know, but I don't have control over the version at work).
Thanks.
Clarification: Since I cannot update PS to v2, I can't install separate applications either. Is there a way to do this with native commands?
Set-WindowPosition – set any one of (or all of) top, left, width, height on a window … or maximize/minimize/restore
Get-WindowPosition – get the position (kind-of redundant, actually, since the Window object has it’s position as a property)
http://wasp.codeplex.com/
This works:
(Get-Host).UI.RawUI
$a = (Get-Host).UI.RawUI
$a.BackgroundColor = "white"
$a.ForegroundColor = "black"
$size = (Get-Host).UI.RawUI.WindowSize
$size.Width = 80
$size.Height = 30
(Get-Host).UI.RawUI.WindowSize = $size
But this doesn't:
$position = (Get-Host).UI.RawUI.Windowposition
$position.X = 0
$position.Y = 30
(Get-Host).UI.RawUI.Windowposition = $position
Just in case you are doing this on your own or your workplace allows open source modules:
I used the UIAutomation powershell module (http://uiautomation.codeplex.com/). Here is my powershell script to move a window to another monitor(which required going to normal and maximize modes).
Start-Process Chrome
##orient new chrome window in full screen on left monitor
#get reference to new chrome window
$nextWin = Get-UiaWindow -Name "*New Tab*"
#transform window to "restore" mode (make sure window is not maximized)
$nextWin.SetWindowVisualState("Normal")
#move window to left monitor
$nextWin.Move(-1920,0)
#maximize window
$nextWin.SetWindowVisualState("Maximize")
Of course the main takaways here are:
$nextWin.SetWindowVisualState("Normal")
$nextWin.SetWindowVisualState("Maximize")
$nextWin.SetWindowVisualState("Minimize")
And there are quite a few options for getting a window ($nextWin) including a Get-UiaActiveWindow
精彩评论