Reputation: 5276
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
Upvotes: 7
Views: 36257
Reputation:
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.
Upvotes: 15