PowerShell: Cleaning Up Empty ConfigMgr Collections
Nice post by Trevor Sullivan.
Read the full post and get the script here.
Someone recently posted on the MyITforum ConfigMgr mailing list, asking how to delete a bunch of old, empty collections in ConfigMgr. I took this opportunity to write a simple PowerShell script that will do just that. The code simply iterates over all collections, looks to see if each collection has members, and if not, then it prompts the user to delete it.
You’ll need to configure a couple things at the top of the script, before you run it:
-
ConfigMgr server name ($SccmServer)
-
ConfigMgr provider namespace (just replace the last 3 characters with your site code)
-
Add any collection IDs to the $ExcludedCollections array, that you want to explicitly exclude
If you’re really daring, and are absolutely confident that you want to remove all empty collections, you can remove the user confirmation. I’ll leave that up to you, if you’re savvy enough 