[英]How do I make Powershell wait until a command is done before continuing?
My script uninstalls a Windows Store app before installing the newer version. 在安装较新版本之前,我的脚本会卸载Windows应用商店应用。 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
You can do this with the Start-Job
and Wait-Job
cmdlets: 您可以使用
Start-Job
和Wait-Job
cmdlet执行此操作:
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. Start-Job
将启动卸载应用程序的新作业进程。 Wait-Job
will then cause the script to wait until the task is completed before continuing. 然后,
Wait-Job
将使脚本等待任务完成后再继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.