如何查询 SCCM 中某个用户所属的所有集合?

如何查询 SCCM 中某个用户所属的所有集合?

我们很快将会把所有用户帐户移至新域,在此期间,用户帐户将在 SCCM 中获取新的 SMS ResourceID。

我需要做的是查询 SCCM 以查找用户所属的所有集合,以便我可以为新用户帐户复制这些集合,直接会员资格(而不是查询会员资格)是我感兴趣的。找到针对用户的所有广告似乎很容易,但找到他们的集合却很难。

理想情况下,我希望能够通过脚本获取此功能,以便我可以使用第二个脚本将新用户帐户添加到相关集合(已经能够通过脚本添加到集合中)。

目前正在运行 SCCM 2007 R2。

答案1

好的,在阅读了比我以前更愿意阅读的更多的 MSDN 之后,我设法整理了下面这个(混乱的)VBScript,以便从 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

相关内容