liveBook · Manning

Start-Process

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

Start-Process is a PowerShell cmdlet that starts a process and can optionally wait for it to finish.

Start-Process launches an executable or PowerShell script as a separate operating-system process. It is useful when an automation must continue independently of the script that launched it: a watcher can start action scripts without either process failing when the other stops or errors. section 3.3.2

Supply the program through FilePath and its command-line values through ArgumentList. FilePath may be a full path, use an environment-variable path, or name an executable available through PATH. ArgumentList can be one command-line string or an array of strings. When launching a PowerShell action script, invoke the PowerShell executable and pass the script path and values; prefer primitive values such as strings, integers, and Booleans over PowerShell objects. section 9.4.1 section 3.3.2

Choose process controls deliberately:

  • Use NoNewWindow to avoid opening a new window for every unattended action. section 3.3.2
  • Use PassThru to receive the process object and retain process IDs for tracking active action scripts. section 3.3.2
  • Use Wait only when later work needs completion, such as timing a watcher run; do not let unattended automation wait indefinitely without a timeout strategy. section 3.4.1 section 9.4.2
  • Use WorkingDirectory and redirected standard output when an external tool must run from a specific location and its result must be inspected. section 12.3.1

Launch and supervise an external command

Start ping.exe with PassThru, then poll HasExited in a loop. A stopwatch establishes the permitted runtime; if it expires, Stop-Process -Force ends the executable and throw reports failure. This replaces an unbounded wait with explicit timeout handling. section 9.4.2

$RuntimeSeconds = 2
$ping = Start-Process -FilePath 'ping.exe' -ArgumentList 
 'google.com','-n 10' -PassThru
$timer =  [system.diagnostics.stopwatch]::StartNew()
while($ping.HasExited -eq $false){
    if($timer.Elapsed.TotalSeconds -gt $RuntimeSeconds){
        $ping | Stop-Process -Force
        throw "The application did not exit in time"
    }
}
$timer.Elapsed.TotalSeconds
$timer.Stop()

A complete timeout pattern combines PassThru, HasExited, Stopwatch, Stop-Process, and throw to supervise a launched executable. section 9.4.2

Independent processes also create concurrency pressure. A burst of incoming files can launch more action scripts than the system can handle. Track running processes and impose a limit; if workload remains above the automation’s available capacity, reconsider execution speed, concurrency, or workload partitioning. Test realistic bursts with Measure-Command before scheduling recurring runs. section 3.3.2 section 3.4.1

Start-Process also provides a consistent boundary for applications outside PowerShell. It can pass command-line arguments and support output and error capture, enabling integrations such as external visualization tools or Git commands used to compare and synchronize a shared module. section 9.4 section 12.3.1

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Explains arguments, process isolation, monitoring, output redirection, concurrency limits, and timeout-based termination.
Examples
Uses folder-watcher action scripts, ping.exe timing and timeout control, and Git-based module synchronization.
What it assumes
Assumes PowerShell automation familiarity while defining executable paths and command-line argument passing from first use.
What you can do after
Operate external commands and scripts with arguments, completion control, monitoring, output capture, and concurrency safeguards.
How it connects
Connects process launching with Task Scheduler, Measure-Command, Stop-Process, Git, and external applications.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.