I am having problems adding a list of computer accounts to a domain group. And it's not working. Getting "There is no such object on the server" error.
Here's the code:
Option Explicit
Dim strFile, objFSO, objFile, strNTName
Dim strDomain, strComputerDN
Dim objTrans, objComputer, objGroup
' Constants for NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify the input file.
strFile = "C:\GroupAdd\userlist.txt"
' Specify the NetBIOS name of the domain.
strDomain = "NA"
' Bind to the group object.
Set objGroup = GetObject("LDAP://CN=EUC-Admin Rights Clients - All Clients,OU=Users,OU=xxxx,OU=xxxx,OU=Corpfn,DC=Na,DC=Corp,DC=xxx,DC=com")
' Use NameTranslate to convert NetBIOS names to Distinguished Names.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Open text file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 1)
' Read the file.
Do Until objFile.AtEndOfStream
strNTName = Trim(objFile.ReadLine)
' Skip blank lines.
If (strLine <> "") Then
' Append "$" to end of NetBIOS name for computers.
'strNTName = strNTName & "$"
' Convert NT names to Distinguished Names.
' Use the Set method to specify the NT format of the user name.
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strNTName
' Use the Get method to retrieve the Distinguished Name.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to computer object.
Set objComputer = GetObject("LDAP://" & strComputerDN)
' Check if computer is already a member of the group.
If (objGroup.IsMember(objComputer.AdsPath) = False) Then
' Add the computer to the group.
objGroup.Add(objComputer.AdsPath)
End If
End If
Loop
' Close the file
objFile.Close
Here's the code:
Option Explicit
Dim strFile, objFSO, objFile, strNTName
Dim strDomain, strComputerDN
Dim objTrans, objComputer, objGroup
' Constants for NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify the input file.
strFile = "C:\GroupAdd\userlist.txt"
' Specify the NetBIOS name of the domain.
strDomain = "NA"
' Bind to the group object.
Set objGroup = GetObject("LDAP://CN=EUC-Admin Rights Clients - All Clients,OU=Users,OU=xxxx,OU=xxxx,OU=Corpfn,DC=Na,DC=Corp,DC=xxx,DC=com")
' Use NameTranslate to convert NetBIOS names to Distinguished Names.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Open text file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 1)
' Read the file.
Do Until objFile.AtEndOfStream
strNTName = Trim(objFile.ReadLine)
' Skip blank lines.
If (strLine <> "") Then
' Append "$" to end of NetBIOS name for computers.
'strNTName = strNTName & "$"
' Convert NT names to Distinguished Names.
' Use the Set method to specify the NT format of the user name.
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strNTName
' Use the Get method to retrieve the Distinguished Name.
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to computer object.
Set objComputer = GetObject("LDAP://" & strComputerDN)
' Check if computer is already a member of the group.
If (objGroup.IsMember(objComputer.AdsPath) = False) Then
' Add the computer to the group.
objGroup.Add(objComputer.AdsPath)
End If
End If
Loop
' Close the file
objFile.Close