1

We will shortly be moving all our user accounts to a new domain, as part of this the user accounts will pick up new SMS ResourceIDs in SCCM.

What I need to do is to query SCCM for all collections that a user is a member of, so that I can duplicate those for the new user account, Direct Memberships (rather than query memberships) are what I'm interested in. It seems to be pretty easy to find all adverts to a user, but not to find their collections.

Ideally I'd like to be able to get this via a script so that I can then use a second script to add the new user account to the relevant collections (already able to add to collections via a script).

Currently running SCCM 2007 R2.

1 Answer 1

1

Ok, after more MSDN reading than I ever care to do again, here's (a messy) VBScript that I managed to pull together to pull the relevant out of SCCM:

option explicit

DIM strSCCMServer, objSCCM
DIM strUserName, strDomain
DIM strSMSUserID
'Central Site Server
strSCCMServer = "SCCMSERVER01"
'Active Directory domain name
strDomain = "DOMAIN_NAME"
strUserName = InputBox ("Enter User Name")


'Find Site Code
DIM objLoc, Results, Loc
Set objLoc = CreateObject("WbemScripting.SWbemLocator")
Set objSCCM = objLoc.ConnectServer(strSCCMServer, "root\sms")
Set Results = objSCCM.ExecQuery ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true")
For each Loc in Results
    If Loc.ProviderForLocalSite = True Then
        Set objSCCM = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & Loc.SiteCode)
    End If
Next

'Find domain user accounts for strUserName
strSMSUserID = GetUserResourceID(strUserName, strDomain)
If (strSMSUserID = "") Then
    wscript.echo "Error: no account found in " & strDomain & " for userID " & strUserName
    wscript.quit
Else
    wscript.echo strDomain & "\" & strUserName & " = " & strSMSUserID
End If


'Find all direct collection memberships of this account
DIM colCollIDs, objCollResID
Set colCollIDs = objSCCM.ExecQuery ("select * from SMS_CollectionMember_a where ResourceID='" & strSMSUserID & "'")
for each objCollResID in colCollIDs
    DIM instColl
    Set instColl = objSCCM.Get ("SMS_Collection.CollectionID=""" & objCollResID.CollectionID &"""")
    wscript.echo objCollResID.CollectionID & " = " & instColl.Name
next

'Obtain the SMS resource ID for a user account in a domain
Function GetUserResourceID(strUser, strDomain)
    DIM objResID, colResourceIDs
    Set colResourceIDs = objSCCM.ExecQuery ("select ResourceID from SMS_R_User where UserName = '" & strUser &"' AND WindowsNTDomain = '"& strDomain &"'")
    for each objResID in colResourceIDs
        GetUserResourceID = objResID.ResourceID
    next
End Function

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .