Automated creation of ConfigMgr operational collections

Query collections can be used in SCCM to target or give a quick counts of specific device states. For example we could create a query collection that contains all Windows 10 workstations.

Manually creating these types of collections can be quite time consuming especially if you manage multiple sites or hierarchies, therefore automatically generating these query based collections using a script can save a lot of time.

Credit where it’s due

This script borrows heavily from the Set Operational SCCM Collections script by Benoit Lecours from systemcenterdudes.com. Benoit created a wonderful script to create query collections that he commonly requires and shared it on the TechNet gallery.

I wanted to use Benoit’s script on a shared hierarchy and to remove the collection details from the script to allow us to easily manage the collections and queries later without revisiting the script. I decided to use a separate XML file to describe the collections and have included a working sample XML in the GitHub repository.

Download

The script and the sample XML file can be found on GitHub here:

https://github.com/markhallen/configmgr/tree/master/New-CMOperationalCollections

Script details and usage

The script can be run multiple times on the same environment and will only recreate the collections that are missing.

.SYNOPSIS

Create collections in Configuration Manager that are useful for operational monitoring.

.DESCRIPTION

Will accept an XML file of the desired collections and queries and create the collections in Configuration Manager.

.PARAMETER SiteCode

3-character site code

.PARAMETER Path

Full or relative path to the XML file containing the collections and queries

.PARAMETER LimitingCollection

[Optional] Sets the LimitingCollection used for new collections.
[Default] “All Systems”

.PARAMETER Organization

[Optional] allows a default top level directory to be defined. This is useful
for a hierarchy that is shared between distinct departments or organizational units.
The value is also prepended to the collections names to allow each oraganisation to
create collections with unique names.
[Default] “”

.PARAMETER FolderName

[Optional] This is the folder that will contain the operational collections. It will
be in the root of device collections or within the Organization folder if defined.
[Default] “Operational”

.PARAMETER RecurInterval

[Optional] Used in conjunction with RecurCount to set a collection update schedule.
Acceptable values are ‘Minutes’,’Hours’ or ‘Days’.
[Default] “Days”

.PARAMETER RecurCount

[Optional] Used in conjunction with RecurInterval to set a collection update schedule.
[Default] 7

.NOTES

Author: Mark Allen
Created: 18/10/2016
References: Benoit Lecours: Set Operational SCCM Collections
https://gallery.technet.microsoft.com/Set-of-Operational-SCCM-19fa8178

.EXAMPLE

.\New-CMOperationalCollections.ps1 -SiteCode PR1 -Path .\MyCollections.xml
Will create the folder ‘Operational’ in the root node Device Collections.
The collections will be created in the Operational Folder.
EG Device Collections > Operational > <Collections from XML>

.EXAMPLE

.\New-CMOperationalCollections.ps1 -SiteCode PR1 -Path .\MyCollections.xml -LimitingCollection “All Systems” -Organization “MyOrg”
Will create a “Test” folder in the root node of each object type; subfolders will be
created within the relevant folder. Collection names will be prepended by <Organization>
EG Device Collections > MyOrg > Operational > <Collections from XML>
Collections will be prepended by “MyOrg …”

.EXAMPLE

.\New-CMOperationalCollections.ps1 -SiteCode PR1 -Path .\MyCollections.xml -RecurInterval “Days” -RecurCount “14”
A custom refresh interval will be set for all new collections.

XML Schema

Within the query tags we need to substitute the less than symbol < with the HTML equivalent &lt;

<Collections>

<Collection>

<Name></Name>

<Query></Query>

<Description></Description>

</Collection>

</Collections>

You can view the working example here: https://github.com/markhallen/configmgr/blob/master/New-CMOperationalCollections/CMOperationalCollections.xml

2 thoughts on “Automated creation of ConfigMgr operational collections”

  1. Excellent job. The script works perfectly and is professionally written. There is a lot that can be learned from this script. Beside the technicals of how it work, you’ve written a well structured and thought out script.

    Very nice work!

    1. Thanks for the comment Mike. It is really satisfying to know, not only that the script has been helpful to someone else, but that the thought process that went into it is appreciated. You’ve made my day.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please complete the calculation *