While waiting for a task sequence to run on a newly deployed computer, I found that the collection I had deployed the task sequence to had not updated even though I added the computer to the collection. After some investigation, I discovered I had exceeded the recommended threshold for the number of collections that can be enabled for incremental updates, and this was obviously causing some problems with the collection membership evaluation. David O’Brien has a great post describing this issue in more detail here.
I identified a number of collections that were enabled for incremental updates that didn’t really need to be, they were just enabled for that by default when the collections were created. These collections were all nested under different subfolders created to organise my different geographical sites, under a single parent folder in the Device Collections node.
So I wrote a PowerShell script that will identify all the collections contained underneath the parent folder, including all subfolders up to 3 levels deep, and change the collection refresh type to ‘Full Scheduled Update only’ instead of using the incremental updates.
To use the script, simply enter your Site Code, the name of the parent folder, and which refresh type you want to set on all those collections.
<# This script changes the Refresh Type for all collections found nested underneath a specific collection folder, up to 3 levels deep #> $SiteCode = "ABC" $ParentFolderName = "Infrastructure" $NewTypeCode = "2" # For NewTypeCode, enter: # 1, for No Scheduled Update, ie manual updates only # 2, for Full Scheduled Update Only, using default weeekly schedule if not previously enabled # 4, for Incremental Update Only # 6, for Incremental and Full Scheduled Update # Empty the arrays in case script is run more than once in same session $Collections = $null $Collections1 = $null $Collections2 = $null $Collections3 = $null if ($NewTypeCode -eq "1") {$NewType = "No Scheduled Update"} if ($NewTypeCode -eq "2") {$NewType = "Full Scheduled Update Only"} if ($NewTypeCode -eq "4") {$NewType = "Incremental Update Only"} if ($NewTypeCode -eq "6") {$NewType = "Incremental and Full Scheduled Update"} cls # Get Parent FolderID Write-Host "Getting Folder ID of Folder '$ParentFolderName'" $ParentFolderID = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_ObjectContainerNode where Name='$ParentFolderName'" | Select ContainerNodeID $ParentFolderID = $ParentFolderID.ContainerNodeID # Get Parent Folder Collections Write-Host "Getting Collections from '$ParentFolderName'" $CollectionsInParentFolder = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_Collection where CollectionID is in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000' and ContainerNodeID='$ParentFolderID') and CollectionType='2'" $Collections = $CollectionsInParentFolder.Name #Get Child Folder Names Level 1 $CF1 = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_ObjectContainerNode where ParentContainerNodeID='$ParentFolderID'" | Select Name,ContainerNodeID $CF1FolderID = $CF1.ContainerNodeID $CF1FolderName = $CF1.Name if ($CF1FolderName -ne $null) { write-host " Found subfolders: "$CF1FolderName -ForegroundColor Yellow } # Get Child Folder 1 Collections foreach ($CF in $CF1) { $CF1FolderID = $CF.ContainerNodeID $CF1FolderName = $CF.Name Write-Host " Getting Collections from '$CF1FolderName'" -ForegroundColor Yellow $CollectionsInCF1 = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_Collection where CollectionID is in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000' and ContainerNodeID='$CF1FolderID') and CollectionType='2'" $CollectionsCF1 = $CollectionsInCF1.Name $Collections1 += $CollectionsCF1 #Get Child Folder Names Level 2 $CF2 = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_ObjectContainerNode where ParentContainerNodeID='$CF1FolderID'" | Select Name,ContainerNodeID $CF2FolderID = $CF2.ContainerNodeID $CF2FolderName = $CF2.Name if ($CF2FolderName -ne $null) { write-host " Found subfolders: "$CF2FolderName -ForegroundColor Yellow } # Get Child Folder 2 Collections foreach ($CF in $CF2) { $CF2FolderID = $CF.ContainerNodeID $CF2FolderName = $CF.Name Write-Host " Getting Collections from '$CF2FolderName'" -ForegroundColor Yellow $CollectionsInCF2 = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_Collection where CollectionID is in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000' and ContainerNodeID='$CF2FolderID') and CollectionType='2'" $CollectionsCF2 = $CollectionsInCF2.Name $Collections2 += $CollectionsCF2 #Get Child Folder Names Level 3 $CF3 = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_ObjectContainerNode where ParentContainerNodeID='$CF2FolderID'" | Select Name,ContainerNodeID $CF3FolderID = $CF3.ContainerNodeID $CF3FolderName = $CF3.Name if ($CF3FolderName -ne $null) { write-host " Found subfolders: "$CF3FolderName -ForegroundColor Green } # Get Child Folder 3 Collections foreach ($CF in $CF3) { $CF3FolderID = $CF.ContainerNodeID $CF3FolderName = $CF.Name Write-Host " Getting Collections from '$CF3FolderName'" -ForegroundColor Green $CollectionsInCF3 = Get-WmiObject -Namespace "ROOT\SMS\Site_$SiteCode" ` -Query "select * from SMS_Collection where CollectionID is in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000' and ContainerNodeID='$CF3FolderID') and CollectionType='2'" $CollectionsCF3 = $CollectionsInCF3.Name $Collections3 += $CollectionsCF3 } } } $Collections += $Collections1 += $Collections2 += $Collections3 $Collections = $Collections | Sort $Count = $Collections.Count write-host "Found $Count collections" Write-host "Changing the Refresh Type for all collections!" -ForegroundColor Magenta foreach ($Collection in $Collections){ $Coll = Get-WmiObject -Class SMS_Collection -Namespace root\sms\site_$SiteCode -Filter "Name ='$($Collection)'" $Coll.Name if ($Coll.RefreshType -eq 1) {$Type = "No Scheduled Update Set"} elseif ($Coll.RefreshType -eq 2) {$Type = "Full Scheduled Update Only"} elseif ($Coll.RefreshType -eq 4) {$Type = "Incremental Update Only"} elseif ($Coll.RefreshType -eq 6) {$Type = "Incremental and Full Scheduled Update"} else {$Type = "Unknown"} write-host " Currently: $Type" -ForegroundColor DarkCyan Write-host " Changing to: $NewType" -ForegroundColor Cyan $Coll = [wmi]$Coll.__PATH $Coll.RefreshType = $NewTypeCode $Coll.put() | Out-Null }