PowerShell - get process ID of called application

Solution 1:

Use Start-Process with the -PassThru argument like this:

$app = Start-Process notepad -passthru
Wait-Process $app.Id

Solution 2:

More succinct:

# Starts Notepad and returns the ID
(Start-Process Notepad -passthru).ID