In System Center Configuration Manager (SCCM), managing collections of users or devices is a crucial task for IT administrators. Two of the key PowerShell cmdlets used for this purpose are Get-CMCollection and Set-CMCollection. The former is used for retrieving and displaying the details of collections, while the latter is used for modifying various properties associated with a collection. These are essential for automating routine tasks, ensuring consistency, and keeping the configuration management environment up to date.
The Get-CMCollection cmdlet is designed to fetch device or user collection objects. It plays a vital role in organizing resources within SCCM, allowing administrators to view current collection details and perform operations on them. By retrieving these collections, administrators can review settings, verify membership criteria, and audit system configurations.
When using Get-CMCollection, you can retrieve:
Typical scenarios where Get-CMCollection is useful include:
Here is a practical example of how to retrieve a collection by name:
# Retrieve a user or device collection by its name
Get-CMCollection -Name "Test Collection"
You can also search for a collection using its unique identifier:
# Retrieve a collection by its Collection ID
Get-CMCollection -CollectionId "XYZ00001"
The Set-CMCollection cmdlet is used to update and configure properties of an existing collection. Whether you want to rename a collection or update its limiting settings, refresh schedules, or other attributes, this command offers the flexibility to modify the collection to meet current administrative requirements.
Some of the primary modifications using Set-CMCollection include:
Administrators use Set-CMCollection for various operations, such as:
The following example demonstrates how you can rename a collection:
# Retrieve the collection and then rename it using the Set-CMCollection cmdlet
$userCollection = Get-CMCollection -Name "testUser"
Set-CMCollection -InputObject $userCollection -NewName "newTestUser"
In this example, the limiting collection is updated to restrict the pool of resources:
# Update the limiting collection for a specific collection by its Collection ID
Set-CMCollection -CollectionId "XYZ00001" -LimitingCollectionId "ABC00001"
Changing how and when the collection updates its membership can be essential. In this example, the refresh type is updated:
# Update the collection refresh type to periodic so that membership is updated based on a schedule
Set-CMCollection -CollectionId "XYZ00001" -RefreshType Periodic
For larger environments, administrators might need to update multiple collections simultaneously. The process often involves importing data from a CSV file and iterating over each entry:
# Import a CSV file containing old and new collection names, then rename each collection
$Collections = Import-Csv -Path "C:\temp\CollectionRename.csv"
foreach ($Collection in $Collections) {
try {
$Result = Set-CMCollection -Name $Collection.OldCollectionName -NewName $Collection.NewCollectionName -PassThru -ErrorAction Stop
Write-Host "Renamed '$($Collection.OldCollectionName)' to '$($Collection.NewCollectionName)'" -ForegroundColor Green
}
catch {
Write-Error "Error renaming '$($Collection.OldCollectionName)' to '$($Collection.NewCollectionName)'"
}
}
Before running these cmdlets, make sure your environment is properly set up:
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1"
Set-Location ABC:
Replace "ABC" with your actual site code.
Adequate permissions are essential for retrieving and modifying collections. Always ensure you have the correct administrative rights before executing these cmdlets since both reading and updating collection properties require security privileges within SCCM.
Administrators should always test any changes in a lab or development environment before applying them to production systems. This cautious approach helps prevent unintended disruptions and allows you to verify that your scripts function as expected.
After applying changes with Set-CMCollection, verify the success of your operation by using Get-CMCollection again to retrieve the collection details. Additionally, update membership if necessary:
# Force the collection to update its membership, particularly if the collection is query-based
Update-CMCollectionMembership -CollectionId "XYZ00001"
The following table provides a side-by-side comparison of the two cmdlets, highlighting their primary functions and common use cases:
Aspect | Get-CMCollection | Set-CMCollection |
---|---|---|
Primary Function | Retrieves device or user collection objects | Updates and configures properties of existing collections |
Usage | Listing, filtering, and auditing collections | Renaming collections, setting limiting collections, modifying refresh behavior |
Parameters | Name, CollectionId, CollectionType | InputObject, NewName, LimitingCollectionId, RefreshType, Comment |
Returns | Collection object details for further processing | Updated collection objects, optionally with confirmation output (PassThru) |
Typical Commands |
|
|
Beyond the basic functionalities, advanced scenarios using Get-CMCollection and Set-CMCollection can streamline complex administrative tasks:
In large-scale environments where hundreds or thousands of collections exist, combining both cmdlets in PowerShell scripts enables automated audits and bulk updates. For example, administrators can create scripts that:
The power of these cmdlets is magnified when used in conjunction with related SCCM PowerShell commands. For instance, once you retrieve a collection using Get-CMCollection, you might use additional cmdlets to inspect settings in greater detail. An example is using:
# Retrieve extended settings for a collection
Get-CMCollection -CollectionId "XYZ00014" | Get-CMCollectionSetting -CollectionType Device
This integration allows detailed verification and configuration of device management settings such as power management and maintenance windows.
Many collections in SCCM are query-based, meaning their membership is determined by a dynamic query. While the basic Set-CMCollection cmdlet is sufficient for many updates, advanced scenarios might require the use of specialized cmdlets to modify the underlying query expressions directly. It is important to ensure that queries are correctly formatted and error-free, as improper queries might lead to incomplete or incorrect collection membership.
In a dynamic IT environment, automation is key. Scripts that incorporate both Get-CMCollection and Set-CMCollection should be designed to handle errors gracefully. Common practices include:
As you implement these cmdlets in your daily operations, consider the following practical tips:
Suppose an organization requires that all device collections with obsolete naming be updated to reflect new departmental structures. A well-planned PowerShell script would:
By automating such processes, IT departments can not only save significant time but also minimize errors that can occur with manual modifications.
In summary, Get-CMCollection and Set-CMCollection are indispensable PowerShell cmdlets for managing collections in SCCM. They empower administrators to retrieve detailed information about device and user collections, and to perform essential updates that keep the collections current and correctly configured. By following best practices such as preliminary environment setup, permission verification, and extensive testing in lab environments, IT professionals can streamline their workflow, reduce manual errors, and maintain a robust configuration management system. The integration of these cmdlets with other SCCM PowerShell commands further enhances the overall efficiency, making it easier to automate complex tasks and manage large deployments effectively.