Hi, I have the following script which pulss a Canonical Name for a security group from a databse. I am trying to use adsNameTranslate to translate the groups CN to it's distinguished name so I can add a user to that group programmatically. Here is the code I am working with. The script does not error when debugging so I believe the script is having difficulty when it gets to this point in the script.
' Get the DN of the group
strGroupDN = adsNameTranslate.Get(ADS_NAME_TYPE_1779)
Your help is greatly appreciated.
************************************************************************************
Option Explicit
Dim rsGrp, strGroup, strGroupDN, strUser, bDebug
Dim strUsr, adsDomain, sGrp, sDomain, adsGroup, strUserDN, strNTGRPDN
Dim sSQL, conSam, sConSam, adsNameTranslate, strNTGRPName
'*******************************************************************************
' Build Database connection strings
'*******************************************************************************
Set conSam = CreateObject("ADODB.Connection")
sConSam = "Provider=SQLOLEDB.1;Password=samadmin;Persist Security Info=True;User ID=samadmin;Initial Catalog=SAM;Data Source=STLAPP1\SAINT"
'*******************************************************************************
' Open Database connections
'*******************************************************************************
conSam.Open sConSam
If bDebug = False Then
On Error Resume Next
End If
Set rsGrp = CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM vwAddToSoiGrp"
rsGrp.Open sSQL, conSam
strGroup = ""
UpdateStatus "Adding Users to SOI group(s)"
Do While Not rsGrp.EOF
Set strGroup = rsGrp("Name")
Set strUser = rsGrp("Unique_Identifier")
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify the NetBIOS name of the domain and the NT name of the user.
'strNTGRPName = " & strGroup & "
' Use NameTranslate to look up the group in the directory
Set adsNameTranslate = CreateObject("NameTranslate")
' Specify the GC for quick lookups
adsNameTranslate.Init ADS_NAME_INITTYPE_GC, vbNull
' Set the group name into NameTranslate
' Specify unknown format to have object determine
adsNameTranslate.Set ADS_NAME_TYPE_UNKNOWN, strGroup
' Get the DN of the group
strGroupDN = adsNameTranslate.Get(ADS_NAME_TYPE_1779)
' Bind to group object
Set adsGroup = GetObject("LDAP://" & strGroupDN)
' Set the user name into NameTranslate
adsNameTranslate.Set ADS_NAME_TYPE_UNKNOWN, strUser
' Get the DN of the user
strUserDN = adsNameTranslate.Get(ADS_NAME_TYPE_1779)
' Bind to the user object
Set adsUser = GetObject("LDAP://" & strUserDN)
' Add user to group
adsGroup.Add adsUser.ADsPath
rsGrp.MoveNext
Loop
rsGrp.Close