Skip to main content

trickling members from one collection to another collection in configmgr

UPDATE: one of my coworkers was using this script to push out a hefty backup agent.  he couldn’t get it to run so while looking at it, i realized the last if/then condition was flawed.  it was looking for members of a compared object when no comparison was issued.  if the second collection is empty and the first collection is greater than the number of clients to send at once, it would fail.  anyway, all fixed.

1000 clients.
1 gb payload.

generally not the situation you want to be in when you’re deploying something over configmgr.  it’s not that it can’t handle it.  there are just certain provisions you have to take so that you do not overwhelm your distribution point(s).  one way to get through this to break down your collection into multiple collections and tie advertisements to them.
an easier way to manage this would be to percolate members from one collection into another.  if you’ve been around awhile, you may remember the script that rick jones wrote to do just this.  you can get it HERE.
the concept is fantastic.  i give props to the guy.  there were some minor things about it that i wasn’t happy about.  basically, it chooses random members of the source collection without depleting the source collection.  because of this, it’s entirely possible to retrieve the same member thus reducing amount of members to trickle in per pass.  anyway, aside from that, it works pretty well.
i wrote a new script in powershell to do the same thing except in a different way.  it works like this:
  • find the specified source and destination collection by name
  • compare the objects in both collections, deriving a list to add to the destination
  • add a specified number of objects
instead of writing query rules, it uses direct membership rules with the object’s resourceid.  once complete, it refreshes the destination collection.  it’s to be used with a scheduled task specified at whatever interval you choose.  my only warning is not to kick it off in swift succession.  there’s some lag time after the collection refresh occurs.  if you query the collection members before the refresh is complete, you’ll end up populating the previous collection members.  bad.  i’m not sure if there’s a negative affect, but empty direct membership rules will show up.  :/
i haven’t tried it with sms 2003.  i presume it would work.  anyway, the script is below.  let me know what you think.
# -------------------------------------------------------------------------------------------------------
# Author: Marcus C. Oh
# Name: sccm_tricklecollection.ps1
# Date: 2/3/2009
# Desc: Adds objects from source collection to destination collection
# -------------------------------------------------------------------------------------------------------

# Variables ---------------------------------------------------------------------------------------------
$sSMSServer = 'mySMSServer'    # SMS Server
$sFirstCollection = 'mySourceCollectionName'    # Source collection
$sSecondCollection = 'myDestinationCollectionName'    # Destination collection
$iNumberOfMembers = 10    # Number of members to add to destination collection per execution

# Functions ---------------------------------------------------------------------------------------------

# Retrieves the SMS site code
    function Get-SMSSiteCode([string]$sSMSServer) {
        $oSMSPath = Get-WmiObject -Namespace 'root\sms' `
            -Query 'select * from sms_providerlocation where providerforlocalsite = true' `
            -ComputerName $sSMSServer | Select-String sitecode
        $Script:sSiteCode = $oSMSPath.ToString().Split("""")[1]

# Main --------------------------------------------------------------------------------------------------

Trickle Collection --------------------------------------------------------------------------------------
SMS Server Name:     [$sSMSServer]
Source Collection:     [$sFirstCollection]
Dest Collection:    [$sSecondCollection]
Members to Add:        [$iNumberOfMembers]


Get-SMSSiteCode $sSMSServer

Write-Host "Retrieved SMS site code - $sSiteCode.  Searching collections..."

# Get a list of collections and find the objects to build the collection list.
$oCollections = Get-WmiObject -ComputerName $sSMSServer  -Namespace "root\sms\site_$sSiteCode" -Class 'SMS_Collection'
$oFirstColl = $oCollections | Where-Object { $_.Name -eq $sFirstCollection }
$oSecondColl = $oCollections | Where-Object { $_.Name -eq $sSecondCollection }

Write-Host "Retrieved main collection and trickle collection.  Retrieving members..."

# Grab the Resource IDs of the first collection
$oFirstCollMembers = Get-WmiObject -ComputerName $sSMSServer -Namespace "root\sms\site_$sSiteCode" `
    -Query "select * from SMS_CM_RES_COLL_$($oFirstColl.CollectionID)" | Select-Object $_.ResourceID

# Again for the second collection
$oSecondCollMembers = Get-WmiObject -ComputerName $sSMSServer -Namespace "root\sms\site_$sSiteCode" `
    -Query "select * from SMS_CM_RES_COLL_$($oSecondColl.CollectionID)" | Select-Object $_.ResourceID

Write-Host "Retrieved members of both collections.  Comparing objects..."

# Create an object to hold the collection rule
$oCollRule = [wmiclass]"\\$sSMSServer\root\sms\site_$($ssitecode):sms_collectionruledirect"
$oCollRule.PSBase.Properties["ResourceClassName"].Value = "SMS_R_System"

# Only execute if the second collection has members already
if ($oSecondCollMembers -ne $null) {
    #Compare the objects to see what is not in the second collection
    $oComparedMembers = Compare-Object -referenceObject $oFirstCollMembers -differenceObject $oSecondCollMembers `
        -SyncWindow 2000 -property 'ResourceID' | `
        Where-Object { $_.SideIndicator -eq '<=' } | `
        Select-Object $_.ResourceID
    if ( $oComparedMembers -eq $null ) {
        Write-Host -foregroundcolor Red "No members to add.  Exiting..."
    } else {
        Write-Host "Found members to add.  Continuing..."
    Write-Host "Objects compared.  Adding members from source collection to destination collection...`n"
    # Add anything missing from the first collection, to the second collection
    if ( ($oComparedMembers | Measure-Object).Count -le $iNumberOfMembers ) {
        $oComparedMembers | `
            ForEach-Object {
                Write-Host -foregroundcolor Yellow "`tAdding Resource ID: $($_.ResourceID) to $sSecondCollection."
                $oCollRule.PSBase.Properties["ResourceID"].Value = $_.ResourceID
                $oSecondColl.AddMembershipRule($oCollRule) | Out-Null
    } else {
        if ($oComparedMembers -ne $null) {
            $oComparedMembers[0..$iNumberOfMembers] | `
            ForEach-Object {
                Write-Host -foregroundcolor Yellow "`tAdding Resource ID: $($_.ResourceID) to $sSecondCollection."
                $oCollRule.PSBase.Properties["ResourceID"].Value = $_.ResourceID
                $oSecondColl.AddMembershipRule($oCollRule) | Out-Null
        } else {
            Write-Host -foregroundcolor red "There are no new members to add.  Exiting..."

} else {
    # Since the second collection is blank, send all values from the first through
    Write-Host "Nothing to compare.  Adding members from source collection to destination collection..."
    if ( ($oFirstCollMembers | Measure-Object).Count -le $iNumberOfMembers ) {
        $oFirstCollMembers | `
            ForEach-Object {
                Write-Host -foregroundcolor Yellow "`tAdding Resource ID: $($_.ResourceID) to $sSecondCollection."
                $oCollRule.PSBase.Properties["ResourceID"].Value = $_.ResourceID
                $oSecondColl.AddMembershipRule($oCollRule) | Out-Null
    } else {
        $oFirstCollMembers[0..$iNumberOfMembers] | ForEach-Object {
            Write-Host -foregroundcolor Yellow "`tAdding Resource ID: $($_.ResourceID) to $sSecondCollection."
            $oCollRule.PSBase.Properties["ResourceID"].Value = $_.ResourceID
            $oSecondColl.AddMembershipRule($oCollRule) | Out-Null

# Refresh the collection
$oSecondColl.RequestRefresh($False) | Out-Null

Write-Host -foregroundcolor green "`nMember addition complete."


  1. Wow. Great script. Is that what you were doing all day at SMUG? -- Matthew

  2. thanks! it was good seeing you. you ran off before i could say bye. @ smug i was on facebook all day. who isn't? come on! :)


Post a Comment

Popular posts from this blog

how to retrieve your ip address with powershell...

update: this is how it’s performed in powershell v3 as demonstrated here.(get-netadapter | get-netipaddress | ? addressfamily -eq'IPv4').ipaddress update: this is by far the easiest.PS C:\temp> (gwmi Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null }).ipaddress
are you laughing yet?  i know you probably find this topic amusing.  it's really interesting though.  whenever you get over it, i'll do this in the standard cmd.exe interpreter and then in powershell to show you what kind of coolness powershell does.done?  okay, good.  this is an interpretation of a demo that bob wells did at our smug meeting.  hope you like it.i should tell you, it's not as simple as the title would lead you to believe.  i like doing that little slight-of-hand thing since it gives the impression that i'm painting a very easy target on my back for your criticism (though it's probably true in other ways)!  the idea is that we want to retrieve just the ip ad…

understanding the “ad op master is inconsistent” alert

i use the term “understanding” loosely.  this is by far no definitive guide on this particular alert, just a few things i have picked up in my attempt to understand it.let’s look at the context of the alert:The Domain Controller's Op Master is inconsitent. See additional alerts for details.
first of all, it gives very little information.  the only particularly useful detail is that it indicates which server is having the issue.  other than that, just a spelling error as there are no additional critical alerts to look at for details.this rule, as you know, comes from a sealed mp.  therefore, we can’t modify anything in it except the overrides.  the couple i’ve tinkered with are:interval (sec) log success event to begin with, interval (sec) is just set way too high.  the default is 60 seconds.  why on earth would anyone want to know that your op master consistency may be off, every minute?  actually, i could think of a few reasons, but really, it’s overkill.  the way the script works…

sccm: content hash fails to match

back in 2008, I wrote up a little thing about how distribution manager fails to send a package to a distribution point. even though a lot of what I wrote that for was the failure of packages to get delivered to child sites, the result was pretty much the same. when the client tries to run the advertisement with an old package, the result was a failure because of content mismatch.I went through an ordeal recently capturing these exact kinds of failures and corrected quite a number of problems with these packages. the resulting blog post is my effort to capture how these problems were resolved. if nothing else, it's a basic checklist of things you can use.DETECTIONstatus messagestake a look at your status messages. this has to be the easiest way to determine where these problems exist. unfortunately, it requires that a client is already experiencing problems. there are client logs you can examine as well such as cas, but I wasn't even sure I was going to have enough material to …