Script to create Computer Accounts

K

KD

I want to create several computer accounts called
Computer-0001 through Computer-1000.

Here is a sample VBS Script that works but does not
include the 0's which I want to incorporate. The script
only creates Computer-1 instead of Computer-0001. Anyone
have any suggestions? Thanks!!!

Set objRootDSE = GetObject ("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://ou=Test," & _
objRootDSE.Get("defaultNamingContext"))
For i = 1 To 20
Set objLeaf = objContainer.Create
("Computer", "cn=Computer-" & i)
objLeaf.Put "sAMAccountName", "Computer-" & i
objLeaf.SetInfo
Next
WScript.Echo "20 Computers Created."
 
T

Tomasz Onyszko

KD said:
I want to create several computer accounts called
Computer-0001 through Computer-1000.

Here is a sample VBS Script that works but does not
include the 0's which I want to incorporate. The script
only creates Computer-1 instead of Computer-0001. Anyone
have any suggestions? Thanks!!!
below is Your script with some modification :)
=======
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."
 
G

Guest

Thank you Very Much!!!
-----Original Message-----

below is Your script with some modification :)
=======
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."


--
Tomasz Onyszko [MVP]
(e-mail address removed)
http://www.w2k.pl
.
 

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