Script to add computer accounts.

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."
 
T

Tomasz Onyszko

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

KD

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top