Powershell

How to Use the Wait-Process (Microsoft.PowerShell.Management) Cmdlet in PowerShell?

The cmdlet “Wait-Process” waits for other processes to be stopped before accepting another input, or it will move to the next command. This cmdlet only works on local computers. When no parameter exists, then it will wait for an undefined amount of time. It suppresses the PowerShell console until the specified process is stopped. A process can be piped or specified to the “Wait-Process” cmdlet using the process name or its ID.

This post will explain the “Wait-Process” cmdlet in-depth.

How to Use the Wait-Process (Microsoft.PowerShell.Management) Cmdlet in PowerShell?

To wait for a process in PowerShell, first, specify the “Wait-Process” cmdlet. Then, use the process by its name or ID. After that, mention the “-Timeout” parameter to specify the time to wait for a process. The “Wait-Process” cmdlet is only supported on PowerShell version 7.3.

To learn further about the stated cmdlet, overview the below-given examples.

Example 1: Use the Wait-Process Cmdlet to Wait for Specified Time
Execute the below-stated command to wait for a specified period of time:

Wait-Process -Name explorer -Timeout 10

According to the above command:

  • First, use the “Wait-Process” cmdlet.
  • Then, place the “-Name” parameter and assign it a process.
  • Lastly, use the “-Timeout” parameter and provide it a specific time:

Example 2: Use the Wait-Process Cmdlet to Wait for Two Processes
In order to wait for two processes, simply, specify the two processes separated by a comma to the “-Name” parameter:

Wait-Process -Name explorer, CalculatorApp -Timeout 15

Example 3: Use the Wait-Process Cmdlet to Wait for a Process to Stop and Then Display the Text
First, write a text string using the “Write-Output” cmdlet. Then, use the cmdlet “Wait-Process” and mention the process waiting to be stopped. Lastly, add a “Write-Output” cmdlet to display a text that will appear after the termination of the process:

Write-Output "Waiting for the process to stop."
Wait-Process -Name explorer
Write-Output "This will execute after process termination"

We have provided a brief explanation of the “Wait-Process” cmdlet in PowerShell.

Conclusion

PowerShell’s “Wait-Process” cmdlet is used to wait for a process to be stopped before more inputs. A process is specified to the stated cmdlet by using its name or ID. Moreover, this cmdlet only works on local computers. This tutorial has explained PowerShell’s “Wait-Process” cmdlet.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.