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
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