I just finished updating the script I’ve been using to bulk create collections in Configuration Manager. I know there are already many different examples of this same type of script out there, but I figured I’d share my take on it.
The script can be downloaded from my GitHub: https://github.com/ConfigJon/ConfigMgr-Scripts/tree/master/Create-Collections
Create_Collections.ps1
This script can be used to dynamically create user collections, device collections, and folder structure based on information in a CSV file. The script should be run as a user account with rights to connect to and create collections in Configuration Manager. The script should be run on a computer with the Configuration Manager Admin Console installed. The script will automatically search for the ConfigurationManager.psd1 file, attempt to import it, and connect to the specific site.
The script has 3 parameters:
- SiteCode – The site code of the Configuration Manager site
- SiteServer – The name of the primary site server, or sms provider
- CsvPath – The path to the CSV file containing the collection information
The CSV file has 12 columns:
- CollectionName – (Required) – The display name of the collection.
- CollectionType – (Required) – The type of collection to create (valid values: User or Device)
- LimitingCollectionName – (Required) – The name of the collection to be used as the limiting collection
- FolderPath – (Optional) – The folder path where the collection is to be created. If the folder path does not exist, it will be created. If the folder path is left blank, the collection will be placed at the root of Device Collections or User Collections. (Example folder path: Applications\Required)
- Comment – (Optional) – A comment
- ScheduleInterval – (Required) – The interval to be used for collection evaluation. (Example values: Days or Hours)
- IntervalCount – (Required) – The number of intervals between collection evaluation.
- IncrementalUpdate – (Optional) – Used to enable incremental updates (Valid values: Yes or No)
- IncludeCollection – (Optional) – Used to specify collections to include. Specify the name of the collection(s). If specifying multiple collections, separate the names with a semi-colon
- ExcludeCollection – (Optional) – Used to specify collections to exclude. Specify the name of the collection(s). If specifying multiple collections, separate the names with a semi-colon.
- QueryName – (Optional) – Name of the query rule to create
- QueryRule – (Optional) – The query language
An example CSV file can be found along with the script on my GitHub page.