Re: Create Multiple Accounts
- From: "1337squirrel" <1337squirrel@xxxxxxxxx>
- Date: 28 Jul 2006 03:56:44 -0700
1337squirrel wrote:
Babu VT wrote:
Hi Sam,
Check this out
http://www.activexperts.com/activmonitor/windowsmanagement/adsi/samples/#file006.htm
rgds
Babu
"Sam" <Sam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:40C9E836-3859-474F-8649-425F742E9D7E@xxxxxxxxxxxxxxxx
I'm trying to create multiple accounts in an OU called 'Visitors' in a
child
domain called sub.local.net bit I'm not entirely sure how to call up the
child domain. I'm working with:
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetOject("LDAP://cn=Visitors," &_
objRootDSE.Get("defaultNamingContext"))
For i = 1 To 125
Set objLeaf = objContainer.Create("User", "cn=GuestAcc" & i)
objLeaf.Put "SAMAccountName", "GuestAcc" & i
objLeaf.SetInfo
Next
WScript.Echo "125 User accounts created"
Also, I'd like to be able to set the account password & Home directory if
possible. If anybody with a little more experience could shed some light
on
this, pointing me in the right direction or direct me to somewhere with
some
documentation covering the basics of AD scripting I'd be much
appreciative.
Cheers.
That's a good link, and a good start, but here's where some MS 'DOS'
combined with some VBScript makes everything easier.
Disclaimer: ComputerPerformance.co.uk is where I got all my help with
this. They're a treasure trove of AD scripting info!
First, you need to create a .CSV file (Comma Separated Value; use Excel
to create it) The following fields need to be entered in the cells
along the top as listed:
givenName
SN
displayName
sAMAccountName
userPrincipalName
objectClass
userAccountControl
DN
Then, for each new user account, fill in the information directly below
each 'title' cell (I'm just showing examples below):
givenName = John
SN = Doe
displayName = John Doe
sAMAccountName = doejohn
userPrincipalName = doejohn@xxxxxxxxxx
objectClass = user
userAccountControl = 514
DN = cn=John Doe,ou=NewUsers,dc=Domain,dc=com
Note: objectClass and userAccountControl will always stay the same.
The other fields will obviously be different per user account.
(If, for example, you're creating some sort of guest accounts, and ONLY
need a username created, you can strip out 'givenName', 'SN', and
'displayName'. However, to make sure the script works, just fill in
all the fields.)
And finally for the CSV file, I recommend saving a 'template' with just
the 'title' fields, and making it read-only. That way you never mess
with your format when you do a new batch of users.
Now, run the following .bat (or CMD line) command:
csvde -i -f yourfile.csv
This will create each user account in the OU you designated via the
'DN' field of the .CSV file. Finally, you wanted to change the
password for the accounts. This VBScript will do that (as well as
enable the account, since the CSVDE command creates the accounts as
disabled):
'SetPwd.vbs
'VBScript to reset passwords, enable accounts, and set 'chg pwd at next
logon', by cycling through a named OU
'credited to: Guy Thomas at
http://computerperformance.co.uk/ezine/ezine22.htm
'modified by: Eric C.
'----------------------------------------------------------------------------------------
Option Explicit
Dim objOU, objUser, objRootDSE
Dim strContainer, strLastUser, strDNSDomain
Dim intCounter, intAccValue, intPwdValue
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = "OU=NewUsers,"
intAccValue = 544
intPwdValue = 0
strContainer = strContainer & strDNSDomain
set objOU = GetObject("LDAP://" & strContainer)
intCounter = 0
For each objUser in objOU
If objUser.class = "user" then
objUser.SetPassword "<password>"
objUser.SetInfo
objUser.Put "userAccountControl", intAccValue
objUser.SetInfo
objUser.Put "pwdLastSet", intPwdValue
objUser.SetInfo
intCounter = intCounter + 1
strLastUser = objUser.Get ("name")
End If
Next
WScript.echo intCounter & "Users enabled, pwds set, and must chg pwd at
next logon. Value " _
& strLastUser & intAccValue
WScript.quit
The only thing you should have to change in the VBScript is
strContainer = "OU=NewUsers,"< to point to the OU where you put the new accounts.
Hope this helps out!
-Eric
In the VBScript that sets the passwords, I missed that you also have to
change the field >objUser.SetPassword "<password>"< (put your default
password inside the quotes, leaving the quotes in place).
.
- References:
- Re: Create Multiple Accounts
- From: Babu VT
- Re: Create Multiple Accounts
- From: 1337squirrel
- Re: Create Multiple Accounts
- Prev by Date: Re: Newbie Question on Exporting
- Next by Date: Re: Lock computer until process completes
- Previous by thread: Re: Create Multiple Accounts
- Next by thread: Try sending email 5 times?
- Index(es):
Relevant Pages
|