Script to add computer accounts.

  • Thread starter Thread starter KD
  • Start date Start date
K

KD

Thank you so much for the previous post. It worked great.
One more question if you have any suggestion. From the
below script it adds the computer accounts to the Parent
Domain. Do you know the switches to add these to a child
domain? When I change the 1st line
to "LDAP://DC=my,DC=domain,DC=com") it does not work.


Set objRootDSE = GetObject ("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://ou=Test," & _
objRootDSE.Get("defaultNamingContext"))
ibaselen = 4
For i = 1 To 20
t = ""
if len(i) < ibaselen then
t = i
for z= 1 to (ibaselen-len(i) )
t = "0" & t
Next
End if
Set objLeaf = objContainer.Create
("Computer", "cn=Computer-" & t)
objLeaf.Put "sAMAccountName", "Computer-" & t
objLeaf.SetInfo
Next
WScript.Echo "20 Computers Created."
 
KD said:
Thank you so much for the previous post. It worked great.
One more question if you have any suggestion. From the
below script it adds the computer accounts to the Parent
Domain. Do you know the switches to add these to a child
domain? When I change the 1st line
to "LDAP://DC=my,DC=domain,DC=com") it does not work.


Try
<code snipet>
Set objContainer = GetObject("LDAP://ou=Test,DC=my,DC=domain,DC=com")
</code snipet>
instead of

Set objRootDSE = GetObject ("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://ou=Test," & _
objRootDSE.Get("defaultNamingContext"))


optionally You will have to specify DC in child domain to which You will
connect

<code snipet>
strDirectoryServer = "CHILDDOMAINDC"
Set objContainer = GetObject("LDAP://" & strDirectoryServer &
"/ou=Test,DC=my,DC=domain,DC=com")
</code snippet>
 
Again; Many Thanks. Works perfect.

Here is what I used:

Set objRootDSE = GetObject
("LDAP://cn=Computers,DC=my,DC=domain,DC=com")
ibaselen = 5
For i = 20 To 21
t = ""
if len(i) < ibaselen then
t = i
for z= 1 to (ibaselen-len(i) )
t = "0" & t
Next
End if
strDirectoryServer = "CHILDDOMAINDC"
Set objContainer = GetObject("LDAP://" &
strDirectoryServer
& "/cn=Computers,DC=my,DC=domain,DC=com")
Set objLeaf = objContainer.Create
("Computer", "cn=Computer-" & t)
objLeaf.Put "sAMAccountName", "Computer-" & t
objLeaf.SetInfo
Next
WScript.Echo "2 Computers Created."
 
Back
Top