Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add one Group as member of another group

Status
Not open for further replies.

anupamd

IS-IT--Management
Jan 25, 2011
1
NZ
Hey Guys,

I am trying to make one group a member of another group. Input is from Excel. Column A groups needs to be added to Column B groups. Each row and has different groups. I am not very good with VBScripting but have still managed to write something. Seems its not working.

Any help will be appreciated.

Below is the code.

******************************************************
Option Explicit

dim objExcel, objWorkbook, objconnection, objCommand, objTarget, objSource, strTDN, strSDN, intRow

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
On Error Resume Next

intRow = 1

Do Until objExcel.Cells(intRow,1).Value = ""

objTarget = objExcel.Cells(intRow, 1).Value
objSource = objExcel.Cells(intRow, 2).Value
'MsgBox(objTarget)
'MsgBox(objSource)

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://' WHERE objectCategory = 'group' AND sAMAccountName='" & objTarget & "'"
Set objRecordSet = objCommand.Execute

strTDN = objRecordSet.Fields("distinguishedName").value

'MsgBox(strTDN)

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://'WHERE objectCategory='group'AND sAMAccountName='" & objSource & "'"
Set objRecordSet = objCommand.Execute

strSDN = objRecordSet.Fields("distinguishedName").value

'MsgBox(strTDN)

strTDN.Add(strSDN.ADsPath)
objTarget.SetInfo
intRow = intRow + 1
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top