Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task powershell powershell

Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task


Can't tell you why it's doing it, but I think this might work around it:

$proc = Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory"" -Passthrudo {start-sleep -Milliseconds 500}until ($proc.HasExited)

The -Passthru switch will make it return a Process object for the process, and you can test that to see when the process has exited.