This is another one of those articles that I truly hope very few get any use out of, as that will mean very few folks have this problem, and that would be ideal for everyone. Sadly, I seem to attract rare issues, so here I am.
Today’s topic – duplicate and orphaned apps from Patch My PC, and more importantly, how you can find them.
In this article, I will cover:
- How I Got Here
- The Impact
- From the Vendor
- How to Find Duplicate/Orphaned Apps
How I Got Here:
If you didn’t know, you should not deploy PMP apps without an assignment, then assign in Intune, and then let PMP try to detect and carry that assignment forward. This is not best practice. The risk with this method is that, occasionally, the assignments will just not carry forward, and now your app isn’t assigned, resulting in every future iteration also going unassigned until you catch that this has happened.
Long story short, some apps got set up like this, and while we worked to convert them to directly assigned in PMP, I set up an automation that was hunting for apps that dropped their assignments and alerting me to them. This worked by basically looking at apps in Intune made by PMP, looking for the highest version number of each given app, and emailing our ticketing system if it found one such app that had no assignments.
Truth be told, this work had been done for some time, but the automation still proved useful in detecting oddball situations like human errors when deploying apps, so I left it running once a week.
Around mid-October, this alerting started to go a little nuts. It was reporting many apps without assignment, including the same app multiple times at once. Upon investigation, what it was really catching was apps that had been created two or more times, effectively duplicate packages, but only one of them had been assigned.
This still met the detection logic as it saw copies of X app, from PMP, that were the highest version, but that weren’t assigned.
At first this wasn’t too bad, but it became enough apps, especially as none of the old duplicates were getting cleaned up, that I had to shut the automation off.
The Impact:
I want to be clear that this issue is not world-ending.
One copy of the app does always get completely made and assigned, so updates do continue to roll as needed. There is no employee or patching impact.
The issue mainly boils down to two things.
- You now have a pile of growing orphaned apps that will never be cleaned up.
- If you have any Intune-based app deployment reporting, having 6 copies of Zoom will probably mess that up.
From the Vendor:
I want to be clear that the good folks at Patch My PC are working with us on this and, in fact, I’m writing this article at their suggestion. That suggestion was to give the community the tools I’m using to catch the issue.
In short, they are aware, they are investigating, but sadly the attempted fixes to date don’t seem to have stopped it. According to PMP, this issue is very rare and impacting only a select few customers. That sounds like just my luck.
Giving some personal thoughts – I do have a slight fear this is a case of survivor bias. Given my alerting automation and the fact we have PMP connected to multiple tenants deploying something like 1,000+ packages, I have a lot better chance of both having and finding an issue like this. Whereas, a small shop deploying 40 packages might avoid such an issue for months or more just via a roll of the dice, or think nothing of it when it does pop up once a year.
That led me to wonder if this was perhaps just a thing that happens 1 in 1,000 times and I should shrug it off. But I can’t accept that because, if it was true, then my automation would have caught it all along, not started lighting up in mid-October. Clearly, this wasn’t always a problem. Even then, it’s definitely occurring more often than 1 in 1,000, at least for us.
In any case, the folks at PMP agree: This should ideally never happen, and they want to fix it.
Coming full circle, my concern that some may have this issue and simply not know it (or may think nothing of it) led me to propose sharing this script, and if I’m going to do that, then an article to help bring attention to the topic and script only makes sense.
How to Find Duplicate/Orphaned Apps:
Of course, I wrote a script to do this for me.
You can find the script on my GitHub here.
How it works:
- Build a list of tenants to cycle through (this is MSP / multi-tenant friendly).
- Cycle through every tenant, connect, and pull managed apps from Intune.
- Cycle through each app and…
A. Confirm it is from PMP (look to the command line for the PatchMyPC in the install Command)
B. Confirm it has more than the expected count (more on this later) - Assemble each matching app and its desired information into a new table.
- Report on the final results and export to CSV.
What to configure:
- Each tenant and how you want to authenticate to said tenant. This is as simple as plugging in a friendly name, tenant ID, and the app reg and corresponding secret for that tenant that you want to auth as. By default, the script accepts a secret stored in your environment variables, as that’s a simple option for a simple need. If you do not like that authentication method, then I’m sure you know how to plug in your preferred method.
Whatever route you go, you / your app will need at least the “DeviceManagementApps.Read.All” permission. - Your expected app count.
In your PMP packages, you probably set every app (or better yet, use a template) to retain X prior copies of a given app. For example, if X is 3, you should at most have the currently active and scoped app and two prior unscoped versions.
If we cycle through apps and find more than this count, then we know something is amiss.
If you are wondering why I don’t group by name and version, then just look for more than one count of each name/version; The problem is old duplicates. If a duplicate was made n-5 versions ago, but your retention policy is N-2, then the non-orphaned copy of the same version is long gone, having since been cleaned up by the retention policy, but the orphan itself is still there. So, in order to find old orphans, we compare the total to the expected count, rather than looking for duplicates of the same version.
If you don’t utilize/standardize on a retention count, this script will still work well to at least find new duplicates by using the “24-Hour-Count” column as explained below.
What it returns:
Once all is set up, run the script. It connects to the tenants and does its hunt, then it dumps those items to the console for a preview and to a CSV (to the execution path) for more detailed diagnostics. In the CSV you will find…
- Tenant: What tenant it found this app in.
- App Name: The name of the app in question.
- Count: The count of packages for that given app name.
- Publish Dates: The time each package was published.
- AppIDs: The Intune App IDs for said apps.
- 24-Hour-Count: This is the count of copies of said app that were published in the last 24 hours. This is useful for identifying new duplicates that were just created, which I look to when trying to confirm the issue is ongoing. This timing works best for a once-daily sync schedule. If you use something else, adjust the script timing accordingly.
Conclusion:
If you are curious, give the script a run against your environment and see what it tells you. If you have the issue, I’d recommend reporting it for the sake of awareness.
Disclaimer:
The following is the disclaimer that applies to all scripts, functions, one-liners, setup examples, documentation, etc. This disclaimer supersedes any disclaimer included in any script, function, one-liner, article, post, etc.
You running this script/function or following the setup example(s) means you will not blame the author(s) if this breaks your stuff. This script/function/setup-example is provided AS IS without warranty of any kind. Author(s) disclaim all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall author(s) be held liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the script or documentation. Neither this script/function/example/documentation, nor any part of it other than those parts that are explicitly copied from others, may be republished without author(s) express written permission. Author(s) retain the right to alter this disclaimer at any time.
It is entirely up to you and/or your business to understand and evaluate the full direct and indirect consequences of using one of these examples or following this documentation.
The latest version of this disclaimer can be found at: https://azuretothemax.net/disclaimer/
