PS: Windows GUI Automation

Very often in automation you require to bring a running process Window to the front and setting it as the active Window for the user. For this you need to run a script like below where you ensure that specified process is running, once you detect that process is running, you select the process Window and then set it as the active Window with maximized position.

Code:

while (! $IsWindowRunning)
{
    $IsWindowRunning = select-window -ProcessName excel
}

select-window -ProcessName excel | set-windowactive | Set-WindowPosition -maximize

 

In case, you just need to one of have the Window maximized, then you can do as below:

while (! $IsWindowRunning)
{
    $IsWindowRunning
= select-window -Title "excel*"
}

maximize-window -wndname "excel*"

Leave a Reply

Your email address will not be published. Required fields are marked *