Get-AppxPackages

Jordan Hammond Fun Headshot
Jordan Hammond|Updated January 26, 2021
Get-AppxPackages
Get-AppxPackages

Do you know what data you can get from your computer using PowerShell? All of it, you can get all of the data. Because of that, PDQ Inventory has added the ability to use PowerShell as a scanner. It is a scanner to rule all scanners. I am sure you are here for the “How” not the “What,” so let’s take a look at how we can get a list of appx packages we may not want.

List Appx Packages

PowerShell has a built-in command to let you see what appx packages are installed. Spoiler: it’s Get-AppxPackages. You have to love that verb-noun scheme they use! First, let’s add some quick error handling. If you run this against a machine older than Windows 10, the command (Get-Command) won’t exist.

if (-Not(Get-Command Get-AppxPackage -ErrorAction SilentlyContinue)) { throw "Get-AppxPackage does not exist here, I bet if you look at the machine closely you will see that it is not windows 10" }

Now that all of that nerd stuff is out of the way, we can focus on the cool stuff. Let’s grab the appx packages on these machines.

Get-AppxPackage

That was fun, thanks for dropping by!

Okay, okay, I suppose we can make this a little more valuable. If we are looking for AppxPackages we may not need, we first need a list of those we want to keep so they don’t get included. I can not stress this enough. This is an example list, not exhaustive. You will probably want to fine-tune your list to make sure it is ideal for your needs.

$Whitelist = @( '*WindowsCalculator*', '*MSPaint*', '*Office.OneNote*', '*Microsoft.net*', '*MicrosoftEdge*' )

Now that we have the ones we don’t want to be listed, we need to run the list of packages found and remove them. We will accomplish this by setting a variable as $false, and it will switch it to True. That way we can build a pscustom object grabbing the data we want.

ForEach($App in $Packages){ $Matched = $false Foreach($Item in $Whitelist){ If($App -like $Item){ $Matched = $true break } }

Putting it all Together

Here is the complete script. This one is not in our GitHub for PowerShell scanners. The whitelist is something that we can’t write for everyone, and I am wary of adding scanners that would require customization after it is downloaded. If that changes, then you are not even reading this right now because this paragraph has changed to match the change of heart! I can’t state how awesome that repository is though, you should check it out, and if you have something you want to share, submit a pull request. We would love for the community to be actively involved in making this scanner it’s best possible version.

if (-Not(Get-Command Get-AppxPackage -ErrorAction SilentlyContinue)) { throw "Get-AppxPackage does not exist here, I bet if you look at the machine closely you will see that it is not windows 10" } ##Get Online Provisioned Packages $Packages = Get-AppxPackage ##Create Your Whitelist $Whitelist = @( '*WindowsCalculator*', '*MSPaint*', '*Office.OneNote*', '*Microsoft.net*', '*MicrosoftEdge*' ) ##Remove all Applications in your whitelist ForEach($App in $Packages){ $Matched = $false Foreach($Item in $Whitelist){ If($App -like $Item){ $Matched = $true break } } if($matched -eq $false){ [PSCustomObject]@{ Name = $App.Name Location = $App.InstallLocation } } }

Conclusion

A final word of caution, if you are planning to use this list to remove the applications, take some extra caution. Reinstalling can be a bit of work, so it would be best to avoid that if possible.

Jordan Hammond Fun Headshot
Jordan Hammond

Jordan had spent his life wondering why tasks he didn’t like to do had no options to complete themselves. Eventually he had to make that happen on his own. It turned out that he enjoyed making tasks complete themselves, and PDQ thought that is something he should talk about on the internet while drinking most Thursdays on the PDQ webcast.

Related articles