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

前端 未结 1 1034
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 02:40

I\'ve got a script that\'s I want to run as a scheduled task, but it\'s not doing the thing it\'s supposed to. I\'m trying to call an executable with Start-Process and the -

1条回答
  •  时光说笑
    2020-12-19 03:46

    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"" -Passthru
    do {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.

    0 讨论(0)
提交回复
热议问题