Link to home
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
Avatar of Alan_White
Alan_White
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
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

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"
Avatar of jaypappas
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

I'm sorry, can you clarify what you would like please?  I don't quite understand.
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

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

It would be good if you specify all requirements..