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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding list of computer accounts to group

Status
Not open for further replies.

vajpowb

Technical User
Jan 18, 2008
16
US
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
 
Updated the line that was commented out. :)


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
 
Your userlist.txt is probably in unicode. Try this.
>Set objFile = objFSO.OpenTextFile(strFile, 1)
[tt]Set objFile = objFSO.OpenTextFile(strFile, 1[blue],true,-1[/blue])[/tt]

Of course, if the content itself is incorrect, only yourself can check out.
 
I updated..but still getting error.

Error points to this line:
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")

"There is no such object on the server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top