PDQ.com mobilePDQ.com desktop
Support

Get-AppxPackages

Jordan HammondJordan Hammond
·

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 builtin 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 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. If you would like or did like a script for the removal and need something about re-adding the applications, I think there will probably be a blog on that in the future.

This blog post is part of our PowerShell Scanner series.

Ready to put the PowerShell scanner through its paces?

Take our 14-day Free Trial. Feel the power of the PowerShell scanner.
Start a Trial

Don't miss the next post!

How To Play 'The Sneaker Net'

This is a walk through / instruction guide on how to play PDQ.com's 2020 sysadmin day game "The Sneaker Net"

PDQ Deploy
PDQ.com
© 2020 PDQ.com Corporation

Products

  • Deploy
  • Inventory
  • Enterprise SL
  • Pricing
  • Downloads
  • Licensing
  • Buy