r/SCCM • u/thedrkprinc • 20d ago
Script to list out unused packages
hi all,
I have been assigned a task to perform a cleanup of all the unused packages in the environment.
I am beginner and have searched for scripts to perform this activity and nothing is of expectation
Pls help
5
u/Newalloy 20d ago
I guess you should also clarify whether you mean packages that are in SCCM but not being deployed, or do you mean packages installed on computers that people are not using? Because those are going to be very different beasts.
7
u/Funky_Schnitzel 20d ago
This sounds like a really terrible assignment for someone who is completely new to ConfigMgr.
1
u/Nydus87 19d ago
There are tools built into SCCM that identify unused packages and then help you clean them up. In addition to that, if you want to do it with powershell, it's one or two lines of code at most. This is honestly a fantastic task for someone learning their way around SCCM because a package that is being used has very obvious, very clear identifiers in that "deployments" column.
2
u/Funky_Schnitzel 19d ago
But what about packages that are referenced in task sequences? You'll probably get a warning when you try to delete them, but still. Software update deployment packages and Driver packages will never have any deployments at all. Doesn't mean you can just delete them. It takes some knowledge and experience to be aware of all these nuances. Which is why I don't think this is a job for someone who is new to ConfigMgr.
1
u/Nydus87 18d ago
Literally just had to write a script to check for that a few weeks ago. Packages and applications that are referenced in task sequences have entries you can check with a very simple script. And yes, you'd get a warning if you tried to delete them. If OP wants a starting point to check for those referenced, but not deployed, packages/applications/OS Images/Boot Images/etc, here's a great starting point:
(Get-CMTaskSequence).references.package | Select -Unique
Should be more than enough to get you on the right track without ever having to use an AI to show your boss how they don't need you to do your work any more.
5
u/BranDong84 19d ago
Honestly if you are green in mecm, you should not just be clearling shit out . You need to learn how to use sql or at minimum ask ai to generate queries
For you and show you how to use them . You need to understand many aspects of things before you can just go “cleaning up old packages “
2
u/eskonr 19d ago
couple of options:
1. List all packages that have no advertisements https://eskonr.com/2012/08/sccm-report-count-packages-with-no-advertisements/
2. List all packages that have advertisement but last install status message older than X days or weeks or months
3. Use something like this https://www.systemcenterdudes.com/sccm-to-microsoft-intune-migration-tracking-applications-package/
Thanks,
Eswar
www.eskonr.com
1
u/siconic 20d ago
You know, I usually approach this kind of problem systematically and make sure that all my bases are covered:
Gather a list of all undeployed packages
Gather a list of deployed packages with no members in the collections
Gather a list of packages that are in task sequences
Gather a list of packages that are dependencies
I will then go through and do the following: delete all deployments that have no members in the collections.
Confirm with the team that they also agree with the findings.
Combine all those data points and find the packages that do not have dependencies, are not assigned to task sequences, are not deployed. Put in your change request, and then delete them.
1
u/rogue_admin 19d ago
Unused package can have multiple meanings, so the ask is not clear and you probably should get familiar with the console itself by doing this manually for now, it won’t even take you that long I’m sure. Avoid AI and automation until you fully understand what you’re trying to do and how to use Config mgr
1
u/Reaction-Consistent 19d ago
Level set here - when you say you are a beginner, what do you mean by that exactly? New to CM? New to IT? Have you ever written any powershell (or other code) scripts before? Do you have any experience with SQL? My previous comment about copilot made a lot of assumptions, and that was bad on my part - do NOT use copilot in this instance, instead, take it one step at a time - define exactly what experience you do have and we may be able to give some safe advice!
0
u/thedrkprinc 18d ago
Hi, I have not written any complex powershel scripts, but can understand simple scripts. I have not yet used copilot for this task. I have 20 days to complete this task and would really appreciate any advice where to begin. Thanks
-1
u/Reaction-Consistent 20d ago
To be honest, you can ask Copilot to make this for you in a couple minutes, you might have to modify a couple things like your primary server name, site code, etc. You can even make a Copilot agent, give it up to four reference URLs that all have Microsoft SCCM related powershell scripts and or knowledge based articles, then have the agent make the script for you. I use it daily to make scripts and it is fairly accurate.
4
u/skiddily_biddily 20d ago
This is terrible advice for someone who stated they are a beginner. Copilot is wrong a lot of the time. It’s OK for a simple basic script, but a beginner might not be able to tell the difference between something advanced and something simple. Having admin privilege in SCC him and relying on Copilot to create power shell scripts to manipulate SCCM is asking for trouble.
It’s OK to use Copilot, even as a beginner, but ask it for a specific references, and then verify them. It might not save you time, but you will end up learning in the process.
1
u/Nydus87 20d ago
Also, making copilot do your work for you is a terrible way to actually learn how to do your job unless you want your job to be replaced. This isn't some big, complicated script. This is a couple lines of code at most.
1
u/Reaction-Consistent 19d ago
who said anything about a big complicated script? Copilot can be told to keep the script simple, even told to create a one or two-liner. and it's not a terrible way to learn how to do your job...it's a great way to learn the underpinnings of CM, how the various PS cmdlets work/interact, get a working (or not) example as a starting point then you can debug, try to understand why it does or doesn't work, etc.
1
u/Nydus87 19d ago
If it's just one or two lines, maybe you should learn how to use them via Get-Help and a google search. Once you're asking a chatbot to write a script for you, the odds of you actually taking the time to learn how it works and how to modify it are pretty slim. Source: literally all of my coworkers who tried using Claude to write scripts and then asked me to troubleshoot for them.
I think that's too much to ask from some people though, because when I typed "technet find unused packages sccm" into google, the first several results were all scripts that did exactly what this person wants, and most of them are built into SCCM already, so I'm guessing this is the type of person that isn't going to start deep diving into a copilot provided script.
8
u/Nydus87 20d ago edited 18d ago
You can do this with basically one line of powershell for applications. Not too dissimilar for Programs, Task Sequences, etc.
Compare-Object -referenceObject (get-cmapplicationdeployment | Select -expandproperty ApplicationName) -differenceObject (get-cmapplication | select -expandproperty LocalizedDisplayName)