Create ConfigMgr Collections based on Non-Compliant CIs – PowerShell

In this post, I’m going to show how you can use PowerShell to create & update query collections for non-compliant CIs.
To create the Collection Query, you need two pieces of information, the Unique ID and the what Info you want Returned, (Noncompliant or State = 2)

Typical Collection Query for NonCompliant CI:

Each CI has an ID, and each time you update it, the Unique ID changes to match the revision

This means, each time you change the CI, you need to update your Collection Query because the CI Unique ID changes.

To speed up that process, I created a script that looks for all of my CI’s in a category, of the Type “Application” and creates corresponding “Non-Compliant” Collections

Once script has run, I have all my collections:

Now in my lab, it’s not too impressive, as pretty much all of the machines in my lab do not have the software above. But you get the point, this will create a collection of machines that are non-compliant and you can have deployments targeted to remediate.

Code on GitHub

Take it and change it to fit your needs, Change the PreFix for the Collections, and the Limiting Collection, along with the line that grabs the CIs from CM. The script should give you lots of ideas for you building your own script to accomplish your environmental needs.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.