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..."
        exit
    } 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."

Comments

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

    ReplyDelete
  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! :)

    ReplyDelete

Post a Comment

Popular posts from this blog

using preloadpkgonsite.exe to stage compressed copies to child site distribution points

UPDATE: john marcum sent me a kind email to let me know about a problem he ran into with preloadpkgonsite.exe in the new SCCM Toolkit V2 where under certain conditions, packages will not uncompress.  if you are using the v2 toolkit, PLEASE read this blog post before proceeding.   here’s a scenario that came up on the mssms@lists.myitforum.com mailing list. when confronted with a situation of large packages and wan links, it’s generally best to get the data to the other location without going over the wire. in this case, 75gb. :/ the “how” you get the files there is really not the most important thing to worry about. once they’re there and moved to the appropriate location, preloadpkgonsite.exe is required to install the compressed source files. once done, a status message goes back to the parent server which should stop the upstream server from copying the package source files over the wan to the child site. anyway, if it’s a relatively small amount of packages, you can

How to Identify Applications Using Your Domain Controller

Problem Everyone has been through it. We've all had to retire or replace a domain controller at some point in our checkered collective experiences. While AD provides very intelligent high availability, some applications are just plain dumb. They do not observe site awareness or participate in locating a domain controller. All they want is the name or IP of one domain controller which gets hardcoded in a configuration file somewhere, deeply embedded in some file folder or setting that you are never going to find. How do you look at a DC and decide which applications might be doing it? Packet trace? Logs? Shut it down and wait for screaming? It seems very tedious and nearly impossible. Potential Solution Obviously I wouldn't even bother posting this if I hadn't run across something interesting. :) I ran across something in draftcalled Domain Controller Isolation. Since it's in draft, I don't know that it's published yet. HOWEVER, the concept is based off

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.   DETECTION status messages take 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 m