In my example Subtree would create a collection group based on every OU located under the Servers OU (Including the Server OU).
For the OUs in the illustration below you would have a collection group created for the Servers, Print, File, Mail, and SQL OUs.
Then read the following sections for usage and parameter information before running the script.
param( [string]$searchbase, [string]$append, [string]$Limiting Collection = 'All Desktop and Server Clients', [string]$Search Scope = 'Subtree', [string]$Refresh Type = 'Manual' ) $OUS = Get-ADOrganizational Unit -searchbase $searchbase -Search Scope $Search Scope -Filter * -Properties canonicalname foreach ($OU in $OUS) For my example, I will be copying the script I named “New-OUBased Device Collection.ps1” to the “C:\SCCMScript” directory.
Next, Open the Configuration Manager Console, click the down arrow in the top left corner and choose “Connect via Windows Power Shell” as shown below.
A Power Shell window will now open which will have the Configuration Manager Module for Power Shell loaded and the session will be pointed to the Configuration Manager PSDrive as shown below.
There are 3 options to choose from and they are “Base”, “One Level” or “Subtree”.
If you do not specify this parameter it will default to Subtree.
For example, take the above illustration, if you specified the word “Servers” it would append the word Servers for each collection name and rule name as shown below.This can save a great deal of time if you have many device collections to create.You will need to have the “Active Directory” and “Configuration Manager” modules for Power Shell” installed on the computer you are running this script from.Refresh Type- This parameter lets you set the option to “Use incremental updates for this collection”. Choosing Manual leaves the box unchecked (shown below). If this parameter is not specified the default is Manual.Now that I have explained all of the parameters, let’s run the script.