Monthly Archives: October 2009

One of the new Cmdlets introduced with PowerShell v2 is called Start-Process. It starts a process on the local computer and optionally waits for it to complete if you use the Cmdlet’s Wait switch parameter. Start-Process is implemented by using the Start method of the System.Diagnostics.Process class of the NET Framework.

The first release of Windows PowerShell didn’t came with a Cmdlet like Start-Process. The function below, it is called Start-Process as well, waits for process completion by default. Additionally, the function will wait for all child processes of the process to complete if you use the WaitForChildProcesses switch parameter. Furthermore, the function will not wait infinitely since it supports a Timeout parameter. By default, it will wait 600 seconds for a process (and child processes) to complete. Like Posh v2’s Start-Process the function uses the System.Diagnostics.Process NET Framework class.

So, why wait for child processes? If it is important to wait for process completion, maybe waiting for its child processes to complete matters as well. For example, the Oracle installer invokes Java and terminates while the Java Runtime is still busy installing the software.

Furthermore, I consider a Timeout as mandatory to avoid an infinite waiting due to a hanging process (or child process).

BTW, of course you can use the function in PowerShell v2 too. Remember that the function has two advantages: wait for child processes, and timeout!

Start-Process (PowerShell)

PowerShell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

functionStart-Process

{

Param

(

[string]$FilePath=$(Read-Host'Supply a value for the FilePath parameter'),