7

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 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.