Generating Inventory Collections for Applications using PowerShell

Purpose

The purpose of this article is to provide a comprehensive guide on generating Inventory collections for applications using PowerShell, offering step-by-step instructions and best practices for effectively managing and organizing application collections.

Background

Beyond the common popular applications like Chrome, Adobe Reader, Slack etc. that come in our Package and Collection Library, usually there are a few specific business applications that are critical to the main operations of the company. We often need to create custom collections for this software to know the following:

  • Which computers are missing the software?
  • Which computers have the software installed?
  • Which computers are running an old version?
  • Which computers are running the latest version?

Typically, this results in having to create core collections to manage a specific application like:
Application EXISTS, Application DOES NOT EXIST, Application is the LATEST VERSION, etc.

Resolution

Discovery

It’s important to get a good overview of what’s already installed before we attempt to make a collection for it. In PDQ Inventory, the default Applications Report is one of your best allies in discovering what you have in the environment. Let’s use OneDrive as our example and treat it as a very important application that we need to create a collection to audit and patch regularly.

  1. Open PDQ Inventory

  2. Click Reports and then open the Applications report

  3. Finding the OneDrive application name, we filter on OneDrive (upper-right search box)

  4. We can see that there’s a lot of variation in the deployed version(s) and this means that it hasn’t really been managed and patched regularly

  5. We want to make a collection based on the application name and we're also going to right-click the top of the Version column and select Group By This Column
  6. Sorting by the version, we want to find the latest version to help build my collection. Looking at the results, we see just a few computers that have the latest version 22.186.0904.0001. We could use this, but since we only see a handful of computers this is installed on, we want to confirm that this is the latest production version and not a beta/preview version.

    It turns out that at the time of this writing, version 22.166.0807.0002 is the latest production version for OneDrive. Reference: https://support.microsoft.com/en-us/office/onedrive-release-notes-845dcf18-f921-435e-bf28-4e24b95e5fc0

Implementation

At this point we have the following information that we need to create our collections:

  • Application Name: Microsoft OneDrive
  • Application Version: 22.166.0807.0002

At the bottom of this article, we've included a link for a PowerShell script based on exporting existing collections and variables from PDQ Inventory.

Copy and paste the full contents of the script into a new txt file on your computer and rename the file to Collections.ps1 or another appropriate name.

 Notice in the example below that we've updated the variables $AppName and $AppVersion with the information we just collected

  #Modify the Application Name and Latest Application Version below:
  $AppName = 'Microsoft OneDrive'
  $AppVersion = '22.166.0807.0002'

  ###################################################################
  $ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
  $AppNameVariable = $AppName -replace '\s',''
  $AppVersionVariable = "AppVer$AppNameVariable"
  $AppNameVariable = "AppName$AppNameVariable"
    1. Save and run your PowerShell script. It should output 2 XML files in the same directory as the script
    2. Open PDQ Inventory and go to Options > Variables, then click on Import and navigate to the Variables.xml file that was created and select Open
    3. Close the window and go back to the Main PDQ Inventory window, select File > Import and navigate to the Collections.xml file that was created and select Open
    4. Scroll down and you should see our newly created collections

From here, you can:

  • Deploy to those “OLD VERSION” or “NOT INSTALLED” Inventory groups
  • Create reports based on these collections
  • If a new version of the software is released, we can simply go to Options > Variables and update the version number
  • All our collections for that application will now use the latest version we’ve specified

One additional note, often applications will include the version in the Application Name. Let’s look at Wireshark. Notice that there are version numbers in the Application Name:

This creates a situation where all the application names are unique and if we chose:

  Incorrect - Name is too specific

  • Name: Wireshark 3.6.3
  • Version: 3.6.3

This would ONLY show collections of computers specifically based on Wireshark 3.6.3 installations. The collection logic uses “Application Name STARTS WITH”, so in this case, we would want to remove the version and use the following information in the script:

  Correct - Name is intentionally broad

  • Name: Wireshark
  • Version: 3.6.3

This will correctly generate the collections to find all instances of Wireshark installed.

Conclusion

Our hope is that this script helps folks who are new to PDQ as well as seasoned PDQ veterans with saving time and managing your organization’s core applications. Beyond this article, we do think there is more opportunity for this script to evolve with combining a PDQ Inventory AutoReport to create a csv output to create a Deploy package and use an AutoDeploy schedule to run PDQ Inventory CLI commands to automatically update the custom variables. But that’s for another day. All the best to you from our PDQ family!

For the full Auto-Generated Collections Script, please visit the following link to our community GitHub repository.

Script: Bonus-Content/Article-Content/AutomatingCollectionsPoSh.ps1 at master · pdqcom/Bonus-Content (github.com)

Still have a question or want to share what you have learned? Visit our Community Discord to get help and collaborate with others.