Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
I searched for a while to find an easy way to run a command from a PowerShell script and wait for it to finish. Most of the example I found use Invoke-Expression but this wont wait. In the end I resorted to the tried and true .Net Fx:
# run a command line and wait for it to be done function RunAndWait([string] $command, [string] $arguments) { $proc = New-Object System.Diagnostics.Process $proc.StartInfo.FileName = $command $proc.StartInfo.Arguments = $arguments $proc.Start() $proc.WaitForExit() }
You need to seperate the command (aka FileName) from any arguments, but otherwise this seems to work nicely.
However, PowerGui doesn’t always wait when you are debugging so be careful if you are stepping through your script and expect it to stop in logical places.