user1054637
user1054637

Reputation: 707

Powershell Wait-Process

I have used Wait-Process in the past and it works fine. This time I am trying to close down visual studio gracefully (allow time to save any unsaved files) and once that is completed for notepad to open.

(Get-Process devenv).CloseMainWindow() | Wait-Process | notepad

Unfortunately while Visual Studio does close gracefully, notepad pops up simultaneously with the save files dialog. Why in this instance does Wait-Process not work as per norm. There is a powershell error accompanied which I cannot understand at the moment.

Wait-Process : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:54 (Get-Process devenv).CloseMainWindow() | Wait-Process <<<<

However I have done many DoSomethingA | WaitProcess | DoSomethingB commands which work. I can't figure out the different scenario here.

Upvotes: 1

Views: 2435

Answers (2)

Shay Levy
Shay Levy

Reputation: 126932

CloseMainWindow returns a Boolean value which is piped to Wait-Process, but Wait-Process expects a process object and not a Boolean value. Give this a try

Get-Process devenv | ForEach-Object {
    $null=$_.CloseMainWindow()
    Wait-Process -Id $_.id
    notepad
}

Upvotes: 2

CB.
CB.

Reputation: 60976

Try like this:

Get-Process devenv | % {$_.CloseMainWindow()}; wait-process devenv -ea silentlycontinue ; notepad

Upvotes: 2

Related Questions