Skip to content

Latest commit

 

History

History

Wait-Process

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Wait-Process fails if a process name is not found

When Wait-Process is used with a process name (not a process ID or instance) then it is supposed to wait for all processes with the specified name. Thus, it is used in order to ensure that none is running. But when this is already the case, none is running, Wait-Process fails with an error:

Wait-Process : Cannot find a process with the name "X". Verify the process name and call the cmdlet again.

Workarounds

The straightforward workaround is to specify ErrorAction as Ignore (v3+) or SilentlyContinue:

    Wait-Process Notepad -ErrorAction SilentlyContinue

Yet another workaround which avoids errors is the fake wildcard trick:

    Wait-Process [N]otepad

The wildcard [N]otepad means exactly Notepad and yet Wait-Process works because unlike with literal names it is not designed to fail with wildcards even if processes are not found.

Scripts


  • Microsoft Connect 449181