ArthurR
ArthurR

Reputation: 111

Process id powershell

I want to position two notepad windows by sharing the screen, one window on the right and one on the left. For that, I only found one function that allows you to set the size and the position of a window in a powershell script.

See more here : https://superuser.com/questions/1324007/setting-window-size-and-position-in-powershell-5-and-6

However, using the same process notepad, I thought I would differentiate them with a different id but it doesn't work, both windows are placed in the same place.

Get-Process -Id 21900 | Set-Window -X -8 -Y 0 -Width 976 -Height 1038 -Passthru -Verbose
Get-Process -Id 14392 | Set-Window -X 952 -Y 0 -Width 976 -Height 1038  -Passthru -Verbose

I also tried to do a second function Set-Window2 and use start-job but it also doesn't work.

Get-Process -Id 21900 | Set-Window -X -8 -Y 0 -Width 976 -Height 1038 -Passthru 
Start-Job -Scriptblock {Get-Process notepad | Set-Window -X 952 -Y 0 -Width 976 -Height 1038 -Passthru}
Get-Job

Is there a way to differentiate 2 windows with the same process ?

Upvotes: 2

Views: 305

Answers (1)

marsze
marsze

Reputation: 17055

When you look at Get-Help Set-Window -Parameter Id you will see that it's not accepted as pipeline input (only -ProcessName is):

-Id <Int32>
    Id of the process to determine the window characteristics.

    Required?                    true
    Position?                    named
    Default value                0
    Accept pipeline input?       false
    Accept wildcard characters?  false

So, you have to specify the parameter directly:

Set-Window -Id 21900 -X -8 -Y 0 -Width 976 -Height 1038 -Passthru -Verbose
Set-Window -Id 14392 -X 952 -Y 0 -Width 976 -Height 1038  -Passthru -Verbose

Upvotes: 1

Related Questions