How do I make Powershell wait until a command is done before continuing?

和自甴很熟 提交于 2021-02-08 15:37:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!