how to wait for a powershell command to terminate code example
Example 1: powershell start a process and wait for it to finish
$proc = Start-Process -Wait -FilePath $procPath -ArgumentList $argument
do{sleep 1}while(Get-Process -Name $procName -ErrorAction SilentlyContinue)
Example 2: msiexec wait for completion powershell
Start-Process msiexec.exe -Wait -ArgumentList '/I C:\installers\SQLIO.msi /quiet'