Avatar of jaypappas
jaypappas
 asked on

Query Domain Controller

On Error Resume Next
 
Set objGroup = GetObject _ 
  ("LDAP://CN=sharepoint users ,cn = users,DC=vancesecurity,DC=com")


objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
WScript.Echo "Members:"



For Each strMember in arrMemberOf

  WScript.echo strMember

Next

Open in new window


Here is the Canonical Name
"vancesecurity.com/Centreville-Office/Information Technology/Sharepoint Users"

Attached is a sample screen shot of a member in this group

How do I change the
 ("LDAP://CN=sharepoint users ,cn = users,DC=vancesecurity,DC=com")

to query for members
sample-user.docx
VB Script

Avatar of undefined
Last Comment
prashanthd

8/22/2022 - Mon
Alan_White

The Object tab of the Sharepoint Users group should reveal the DSN for the group.
ASKER CERTIFIED SOLUTION
prashanthd

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
prashanthd

Missed something...try the following
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN

' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=group)(cn=sharepoint users))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedname"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
    ' Retrieve values and display.
    strDN = adoRecordset.Fields("distinguishedname").Value
    Set objGroup = GetObject  ("LDAP://"&strDN)
    
    objGroup.GetInfo
    
    arrMemberOf = objGroup.GetEx("member")
    
    WScript.Echo "Members:"
    
    For Each strMember In arrMemberOf
        
        WScript.echo strMember
        
    Next
    adoRecordset.MoveNext
Loop

' Clean up.
adoRecordset.Close
adoConnection.Close

Open in new window

josika

You start at the right and go left to get the FQDN.

"vancesecurity.com/Centreville-Office/Information Technology/Sharepoint Users"

Would turn into:

"LDAP://CN=Sharepoint Users,OU=Information Technology,OU=Centreville-Office,DC=vancesecurity,DC=com"
Your help has saved me hundreds of hours of internet surfing.
fblack61
jaypappas

ASKER

Open in new window

Open in new window

Open in new window

Now how to add a memeber named "test" to the group by changing this

objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
    Array("cn=test,cn=sharepoint,DC=andrewsinternational,DC=com")



On Error Resume Next
 
Set objGroup = GetObject _ 
  ("LDAP://CN=sharepoint_Users,ou = sharepoint,DC=andrewsinternational,DC=com")


objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
WScript.Echo "Members:"
x=0


For Each strMember in arrMemberOf
  WScript.echo strMember
   
   
   Next

 
objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
    Array("cn=test,cn=sharepoint,DC=andrewsinternational,DC=com")
 
objGroup.SetInfo

Open in new window


-----------------------------------------------------------
Now how to add a memeber named "test" to the group by changing this

objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
    Array("CN=Sharepoint Users,OU=Information Technology,OU=Centreville-Office,DC=vancesecurity,DC=com

")


Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN


Set fso = CreateObject("Scripting.FileSystemObject") 
'pointing to default folder for DTS files
Set folderObject = fso.GetFolder("n:\WORKFLOW\")

Set eFile1 = folderObject.CreateTextFile("LOG.txt",true,false) 



' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on user objects.
strFilter = "(&(objectCategory=group)(cn=sharepoint users))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedname"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

msgbox(strDN)


' Run the query.
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
    ' Retrieve values and display.
    strDN = adoRecordset.Fields("distinguishedname").Value
	
	
    Set objGroup = GetObject  ("LDAP://"&strDN)
    
    objGroup.GetInfo
    
    arrMemberOf = objGroup.GetEx("member")
    
    WScript.Echo "Members:"
    
    For Each strMember In arrMemberOf
        
       ' WScript.echo strMember
        
    Next
    adoRecordset.MoveNext
Loop

objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
    Array("CN=Sharepoint Users,OU=Information Technology,OU=Centreville-Office,DC=vancesecurity,DC=com")
objGroup.SetInfo	
	



' Clean up.
adoRecordset.Close
adoConnection.Close 

Open in new window

josika

I'm sorry, can you clarify what you would like please?  I don't quite understand.
prashanthd

Try the following
dim groupPath
dim userPath

groupPath = "LDAP://CN=sharepoint_Users,ou = sharepoint,DC=andrewsinternational,DC=com"
userPath = "cn=test,cn=sharepoint,DC=andrewsinternational,DC=com"

addToGroup userPath,groupPath

sub addToGroup(userPath, groupPath)
	dim objGroup
	set objGroup = getobject(groupPath)
	
	for each member in objGroup.members
		if lcase(member.adspath) = lcase(userPath) then
			exit sub
		end if
	next
	objGroup.Add(userPath)

end sub

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
prashanthd

Missed LDAP for user
dim groupPath
dim userPath

groupPath = "LDAP://CN=sharepoint_Users,ou = sharepoint,DC=andrewsinternational,DC=com"
userPath = "LDAP://cn=test,cn=sharepoint,DC=andrewsinternational,DC=com"

addToGroup userPath,groupPath

sub addToGroup(userPath, groupPath)
	dim objGroup
	set objGroup = getobject(groupPath)
	
	for each member in objGroup.members
		if lcase(member.adspath) = lcase(userPath) then
			exit sub
		end if
	next
	objGroup.Add(userPath)

end sub

Open in new window

prashanthd

It would be good if you specify all requirements..