Wait for Process to Complete Using PowerShell

# Execute the program. Change the -FilePath argument as needed. $script:exitCode = (Start-Process -FilePath `"setup.exe`" -Passthru -Wait).ExitCode; # Wait for process to complete. Use the Get-Process CmdLet to determine the name # of the process you need to wait for, then change the name of that process as # needed below. $running = $true; while( $running -eq $true ) { $running = ( ( Get-Process | where ProcessName -eq "setup").Length -gt 0); Start-Sleep -s 5 }
1 reply
  1. KC says:

    This is great! I was trying to create an automated visual studio install using the enterprise.exe. The problem with using Start-process -Wait or Out-Null for it is that it launches the vs_installer.exe and then runs dependencies which are attached to the original process so the -wait would run and never end. This way I can spot-pick the installer exe and continue after its done. Great post!

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.