September 2003
Intermediate to advanced
624 pages
15h 49m
English
You want to find the name of a user’s primary group.
Open the Active Directory Users and Computers snap-in.
If you need to change domains, right-click on Active Directory Users and Computers in the left pane, select Connect to Domain, enter the domain name, and click OK.
In the left pane, right-click on the domain and select Find.
Type the name of the user and click Find Now.
In the Search Results, double-click on the user.
Click the Member Of tab.
The Primary Group name is shown on the bottom half of the dialog box.
' This code prints the group name of a user's primary group ' ------ SCRIPT CONFIGURATION ------ strNTDomain = "<DomainName>" ' NetBios Name of the AD domain, e.g. RALLENCORP strUser = "<UserName>" ' e.g. Administrator ' ------ END CONFIGURATION --------- ' Iterate over the user's groups and create a search filter ' that contains each group set objUser = GetObject("WinNT://" & strNTDomain & "/" & strUser & ",user") strFilter = "" for each objGroup in objUser.Groups strFilter = strFilter & "(samAccountName=" & objGroup.Name & ")" next strFilter = "(|" & strFilter & ")" ' Now need to perform a search to retrieve each group ' and their primaryGroupToken strBase = "<LDAP://" & strNTDomain & ">;" strFilter = "(&(objectcategory=group)" & strFilter & ");" strAttrs = "name,primaryGroupToken,cn;" strScope = "subtree;" set objConn = CreateObject("ADODB.Connection") objConn.Provider = "ADsDSOObject" ...