问题
My script uninstalls a Windows Store app before installing the newer version. I need to make sure the uninstall is finished before installing, so how can I make sure I've waited long enough?
Remove-Appxpackage MyAppName
# ~wait here~
Add-Appxpackage .\PathToNewVersion
回答1:
You can do this with the Start-Job and Wait-Job cmdlets:
Start-Job -Name Job1 -ScriptBlock { Remove-Appxpackage MyAppName }
Wait-Job -Name Job1
Add-Appxpackage .\PathToNewVersion
Start-Job
will start a new job process that uninstalls the application. Wait-Job
will then cause the script to wait until the task is completed before continuing.
来源:https://stackoverflow.com/questions/27989736/how-do-i-make-powershell-wait-until-a-command-is-done-before-continuing