Windows 10 – AppX Removal Script Update

      No Comments on Windows 10 – AppX Removal Script Update

AppX Removal Script Update

Hey welcome to my blog and Happy 2018!  Some of you may remember I did an article last year about AppX apps and how they can break Sysprep.  I explained how I ran into the issue and then I went a little further than that and provided a couple scripts to help remove the AppX packages and to remove provisioning of those apps so they don’t install under other accounts.  Surprisingly it’s one of the more popular articles on here.

During my day job I’m constantly working with images for VDI deployments and I’m finding additional apps to remove and new ways to view and sort through them all.  I wanted to detail those as an addition to my previous article.  I also wanted to talk through how most people end up breaking Sysprep and how to avoid doing so altogether.

How not to break Sysprep

Ok so this is a LOT easier than you may think.  There’s 3 rules to follow and if you follow them you should not have issues with AppX and Sysprep.

  1. DO NOT log on more than one account after installing Windows 10.  The first time you boot up after installing Windows 10 it asks you to create a new account.  I usually call it “temp” or something like that since it’s intentionally temporary.  When building an image you usually don’t want to have the “temp” account as the one you use going forward.  You may have even joined the image to the domain and logged on under multiple accounts or even enabled and logged on as the local administrator.  This is the first and most common mistake.  Once you login to other accounts the AppX apps will be installed under the additional user accounts/profiles and has greater potential to cause Sysprep to fail.  AppX apps are provisioned or downloaded on every account you login to.  You can login to multiple accounts but you have to follow the next 2 rules.
  2. If you do logon under other accounts, run the AppX removal scripts under ALL accounts removing the SAME apps from all accounts.  You must run the AppX Removal scripts on every account you logged into on the image.  You must also ensure that you remove exactly the same AppX apps and do not install any additional AppX apps on any of the logged in accounts.
  3. DO NOT delete accounts or profiles from the image until you’ve run the AppX removal scripts.  If you delete an account/profile that has an AppX app deployed it can effectively get stuck.  You may run into a situation where you cannot remove the AppX app because it’s stuck in the database as deployed to an account that no longer exists.

If you follow the above rules you can easily avoid problems with AppX apps and Sysprep.  You have to remember that if the image is network connected then the Windows Store can download and install Sponsored Apps for every account you login to.  If you remove those apps on one account that doesn’t mean those apps are removed from any other accounts you may have logged into.  This is also true for the base AppX apps that get installed natively like Bing News and others.  If you Remove-Package a native Microsoft AppX app but you have logged into another account then you also have to Remove-Package that app on any other accounts you’ve logged into.

For my testing and validation of the following scripts I built a Windows 10 – 1703 and a Windows 10 – 1709 virtual machine in my vSphere 6.5 lab.  They’re both completely vanilla.  I installed Windows 10, installed VMware Tools, downloaded and applied updates from WindowsUpdate and took a snapshot of each so I could break and unbreak them very quickly.  As mentioned previously, Windows 10 forces you to create a user account on first boot after install so I created a “Temp” account.  The local administrator account is disabled by default.  I left them both network connected and did not join a domain.

Which AppX apps are installed for which accounts?

The first thing we need to do is check which AppX apps we have installed and under what accounts.  You will need to set the Execution Policy in Powershell to allow you to run the script first.  So open an elevated Powershell or an elevated Powershell ISE window and run the following command to allow scripts to run.

And after you have finished running the removal scripts on all necessary accounts you should set it back using the below command.

The script below will output the Get-AppXPackage command to a text file at the root of the C Drive.

At the root of the C Drive you should find a text file containing the output which should look something like the below snippet.

You’ll notice this one lists only one “User” account because in this case that’s all I’ve logged in with.  If you’ve logged into the image with more than one account this script output should list multiple users for AppX apps that get deployed per user.  This will help you identify which AppX apps need to be removed because they will cause issues with Sysprep.  I want to qualify that with the following.  There are only certain apps that can be removed without causing issues so please proceed with caution.  Luckily for you I’ve already generated several simple scripts based on what apps can safely be removed.

AppX Removal Script #1 – The Long Version

Noting my previous AppX article, this script is a variation on those scripts that I’ve refined quite a bit.  I came to the realization after writing that article that for a majority of the scenarios I could think of most people would want to remove the particular Installed AppX package as well as remove provisioning so the apps don’t install themselves under new accounts.  So knowing that I condensed both scripts into one and cleaned them up to explicitly remove only what is necessary.  I set only what I typically remove in my own VDI deployments to be removed.  I added some commented out commands if people feel the need to remove Calculator they can.  Although I don’t recommend it of course.  Who doesn’t use Calculator every now and then?

Anyway, I’m assuming here you’ve already set the Execution Policy on your image to Unrestricted.  The following has been tested on Windows 10 – 1703 and Windows 10 -1709.

If you’ve followed the rules I detailed above this script should work without issue.  Remember though that any Sponsored Apps will potentially install themselves through the Windows Store.  The only way to stop that is to disable the components that auto-download updates and Sponsored Apps which I will talk about later in this article.

AppX Removal Script #2 – The Shorter Version

Ok so I’ve seen variations on this script all over the internet.  The problem though is they are usually too heavy-handed and basically just remove everything which of course we don’t necessarily want to do.  Here I’ve adjusted the script according to my curated list of safe to remove AppX apps and included the Sponsored Apps most commonly installed.

Again, I’m assuming here you’ve already set the Execution Policy on your image to Unrestricted.  The following has been tested on Windows 10 – 1703 and Windows 10 -1709.

This script and the first don’t do anything functionally different.  They both remove the same AppX Packages and remove the same AppX Provisioning packages.  The second script actually runs a few Remove-AppXProvisionedPackage commands that it doesn’t need to against provisioned packages that don’t exist since it’s running a loop against the list.  Both the first and second script work perfectly well and allow for customization.  The third script however is just awesome and works in those situations you need to customize what you remove across different images and don’t want to hassle with changing scripts.

AppX Removal Script #3 – The Out-Gridview Version

I like to give credit where credit is due.  A genius on the QA site answered a question of how to quickly remove AppX apps and suggested the use of the Powershell command Out-Gridview.  I’m just sharing someone else’s brilliant use of Powershell here.  This is also by far my favorite method to remove AppX Packages.

Once again, I’m assuming here you’ve already set the Execution Policy on your image to Unrestricted.  The following has been tested on Windows 10 – 1703 and Windows 10 -1709.

This script opens a GUI based dialog box and you just multi-select what you want to remove and click OK to remove the selected AppX apps.  The first part opens a dialog to remove the installed packages.  The second part removes the provisioning packages ensuring that the AppX apps you choose to remove don’t auto-install under new user accounts.  The beauty of this method is you select exactly what you want to remove without having to adjust any scripts.  It’s also a nice and quick way to see which AppX packages or provisioning packages are installed on each user account or to validate that you’ve actually removed what you want to remove.  You can run this again after you’ve removed AppX apps with it and remove additional apps or verify there’s nothing else to remove and you can just hit Cancel to exit the dialog boxes so you don’t remove anything else.

The only downside with this script is you must have a fairly good understanding of which apps you can and cannot remove.  I won’t go into detail too much on that other than to point you to the other scripts to get a good idea of what I would consider safe to remove.  I’ll also share this blog post that has a pretty decent description of most of the AppX packages as well as further suggestions on AppX apps that are safe to remove.


I’ve detailed how to avoid causing the Sysprep issue as well as given you three ways to remove AppX Packages and AppX provisioning Packages.  But wait a minute!  How do I stop the Windows Store from auto-downloading Sponsored Apps or AppX Package updates?  Well there are 3 possibilities here that I’ll briefly describe.

Disable Windows Store Automatic Updates (Registry)

Disable Microsoft Consumer Experience (Registry)

Disable Windows Store InstallService (from an elevated Command Prompt)

Each of these individually may help alleviate issues with AppX and Sysprep but like anything use these with caution.  You will be disabling parts of the Windows Store disallowing certain interaction with the Windows Store.

So there you are.  I’ve given you the tools!  Good luck and I hope this update provides some additional help working through these issues.  Thanks for reading my blog!

Leave a Reply