Introduction

A common reason for a Microsoft Endpoint Configuration Manager (SCCM) environment to become slow is mis-configured collection updates.

A few of the reasons for this might be:

  • The administrator does not know how collections updates work
  • Laziness
  • Migration from SCCM 2007, where Delta updates did not work. This is something that I have seen firsthand with thousands of collections configured for incremental updates.

Accomplishing this for a few collections works fine using the GUI, but if you want to change collection update settings for hundreds, or thousands of collections this is not a viable option.

In this blog post, I provide a Powershell script for configuring the collection update in Microsoft Endpoint Configuration Manager (SCCM).

What is the collection update in SCCM?

To keep collections up to date, they need to update on a set schedule.

There are two different collection updates in Microsoft Endpoint Configuration Manager (SCCM):

Common issues with collection updates

When collection updates are not properly configured, you may see one or more of the following issues:

  • Collections slow to update

Best practices for collections in SCCM

Best practices for collections in SCCM include:

  • Keep the number of collections to a minimum
  • Only use Incremental Updates for collections when required
  • Reduce the complexity of the collection queries
  • Reduce the frequency of collection updates

Keep the number of collections to a minimum

I have seen many customers with thousands of collections. Sometimes, this might be needed, but I would argue in most cases not.

A common reason for many collections is using them for displaying devices or users using query-based collections. In most cases, regular queries can accomplish this.

Only use Incremental Updates for collections when required

Incremental updates are great in the sense that they can update every 5 minutes putting no major strain on the SCCM server.

However, if you have hundreds of collections configured with incremental updates, you will most likely start seeing performance issues. From what I’ve heard, keeping collections configured with incremental updates under 500 is a good idea.

One case that I have seen was when a customer had upgraded from SCCM 2007 to 2012.

In SCCM 2007, they had configured delta updates, which is the old term for incremental updates.

Delta updates did not work well in SCCM 2007, but once they had been migrated to SCCM 2012, they started working, leaving major performance issues in its backwaters.

Reduce the complexity of collection queries

Another common issue I have seen is when the collection queries get overly complicated.

Here are some examples of what you should not have in your collection queries:

  • Like statements. If not specifically required, use Equals to.

Reduce the frequency of collection updates

A general rule of thumb is to not update your collections more than is required.

Also, make sure that you sync the collection update schedule with other updates such as the different discovery methods.

How to find how collections are configured and performing

For starters, have a look at CEViewer (Collection Evaluation Viewer), and the new Management Insights in Microsoft Endpoint Configuration Manager 1910.

If you want to dig deeper, look in the colleval.log file under:

<Installation directory>\Logs

How to configure collection updates using Powershell.

If you need to bulk update the collection updates, use the Powershell script I have created.

The script reads the collections IDs from a file called collections.txt, which needs to be in the same folder as the script and then sets the options.

Collection options, i.e., Incremental Updates, Scheduled Updates, are set using the collection property refreshtype. Depending on what integer is set here, it will set different options. These are the options:

6 = Incremental and Scheduled Updates
4 = Incremental Updates Only
2 = Scheduled Updates only
1 = Manual Update only

The script needs to run with one of these settings and also the collections that are defined in collections.txt. Valid options here are User or Device.

If you want to configure device collections in collections.txt to only update on a schedule, you run this command:

.\Set-CollectionUpdates.ps1 -CollectionType Device -RefreshType 2

Note that if you tick the Schedule a full update on this collection, it will set the value that is set to the collection object.

If you have changed that value in the past, it will use that value, or if you have never changed it, it will use the default value “Occurs every 2 weeks on Thursday effective 2/1/1970 12:00 AM”.

Here is the output of the script.

Powershell script to set Configuration Manager SCCM 2012 collection update

Download the Powershell script from the TechNet Library.

Source code:

<#
.PARAMETER COLLECTIONTYPE
Define the type of collections in the collections.txt file. Valid inputs are Device and User

.PARAMETER REFRESHTYPE
Define the Refresh type for the collection. Valid inputs are:

# The following refresh types exist for ConfigMgr collections 
# 6 = Incremental and Scheduled Updates 
# 4 = Incremental Updates Only 
# 2 = Scheduled Updates only 
# 1 = Manual Update only 
    
.DESCRIPTION
Sets the collection refresh type for all collections defined in a text file.

.NOTES
Author: Daniel Classon
Version: 1.0
Date: 2015/05/18
    
.EXAMPLE
.\Set-Collection_Updates.ps1 -CollectionType Device -RefreshType 2
Will set the collections in collections.txt to "Scheduled Updates only".

.DISCLAIMER
All scripts and other powershell references are offered AS IS with no warranty.
These script and functions are tested in my environment and it is recommended that you test these scripts in a test environment before using in your production environment.
#>

[CmdletBinding()]

Param(
    [Parameter(Mandatory=$True, Helpmessage="Enter the Collection Type")]
    [string]$CollectionType,
    [Parameter(Mandatory=$True, Helpmessage="Enter the Refresh Type")]
    [string]$RefreshType
)

Begin {
    #Checks if the user is in the administrator group. Warns and stops if the user is not.
    if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
        Write-Warning "You are not running this as local administrator. Run it again in an elevated prompt." ; break
    }
    try {
        Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)
    }
    catch [System.UnauthorizedAccessException] {
        Write-Warning -Message "Access denied" ; break
    }
    catch [System.Exception] {
        Write-Warning "Unable to load the Configuration Manager Powershell module from $env:SMS_ADMIN_UI_PATH" ; break
    }
}
Process {
    try {
        $CollectionIDs = Get-Content "collections.txt" -ErrorAction Stop
    }
    catch [System.Exception] {
        Write-Warning "Unable to find collections.txt. Make sure to place it in the script directory."
    }
    $SiteCode = Get-PSDrive -PSProvider CMSITE
    Set-Location -Path "$($SiteCode.Name):\"
    
    $Count = 0

    Foreach ($CollectionID in $CollectionIDs) {
        $Count++
        if ($CollectionType -eq "Device") {
            $Collection = Get-CMDeviceCollection -CollectionId $CollectionID
            $Collection.RefreshType = $RefreshType
            $Collection.Put()
            if ($RefreshType -eq 1) {
                Write-Progress -Activity "Enabling Manual Update only  on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Manual Update only on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
            }
            elseif ($RefreshType -eq 2) {
                Write-Progress -Activity "Enabling Scheduled Updates only on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Scheduled Updates only on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
            }
            elseif ($RefreshType -eq 4) {
                Write-Progress -Activity "Enabling Incremental Updates only on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Incremental Updates Only on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
            }
            elseif ($RefreshType -eq 6) {
                Write-Progress -Activity "Enabling Incremental and Scheduled Updates on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Incremental and Scheduled Updates on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
        }
        } 
        if ($CollectionType -eq "User") {
            $Collection = Get-CMUserCollection -CollectionId $CollectionID
            $Collection.RefreshType = $RefreshType
            $Collection.Put()
            if ($RefreshType -eq 1) {
                Write-Progress -Activity "Enabling Manual Update only  on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Manual Update only on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
            }
            elseif ($RefreshType -eq 2) {
                Write-Progress -Activity "Enabling Scheduled Updates only on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Scheduled Updates only on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
            }
            elseif ($RefreshType -eq 4) {
                Write-Progress -Activity "Enabling Incremental Updates only on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Incremental Updates Only on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
            }
            elseif ($RefreshType -eq 6) {
                Write-Progress -Activity "Enabling Incremental and Scheduled Updates on $CollectionType Collection ID: $CollectionID" -Status "Modified $Count of $($CollectionIDs.Count) collections" -PercentComplete ($Count / $CollectionIDs.count * 100)
                Write-Host "Enabling Incremental and Scheduled Updates on: " $Collection.CollectionID "`t" $Collection.Name -ForegroundColor Yellow
        }
        } 
} 
}  
End {
    Write-Host "$Count $CollectionType collections were updated"  
    Set-Location -Path $env:SystemDrive
}

Conclusion

Powershell is handy when you want to systematically, and with quality change properties in SCCM.

Read my other posts about automation in SCCM using Powershell.

How have you configured collection updates in SCCM? Please leave a comment below :).

References

Related posts

Subscribe to newsletter:

If you want to receive the latest news for MEMCM, Windows 10, and Powershell, please subscribe to my monthly newsletter!

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here