Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Creating AD user accounts for a batch of users

3 views
Skip to first unread message

george

unread,
Apr 18, 2005, 8:00:59 AM4/18/05
to

"Tharaka" <Tha...@discussions.microsoft.com> wrote in message
news:1E51F225-EC45-485C...@microsoft.com...
>I need to create user accounts for large number of users as a batch. I have
> the required username, userlogon name and password in three columns in an
> Exel sheet. How can I read these information in to a script and execute.
>
> Thanks in advance,
>
> Tharaka

One possibility would be to check out the DSADD command in help&support.
It has a ton of parameters (not all of them needed in your case), but you
can easily introduce new columns into your excel, holding those command and
parameter references, export your excel into a text-style cmd. file and run
it.

george


Al Dunbar [MS-MVP]

unread,
Apr 18, 2005, 10:32:35 PM4/18/05
to

"george" <anon...@discussion.microsoft.com> wrote in message
news:OLP2L5AR...@tk2msftngp13.phx.gbl...

Or, alternately, you could check out CSVDE.EXE. This application accepts
input in the form of a csv file (easily generated from an excel
spreadsheet), and creates accounts according to the info provided. Note
that, unless you have a small organization, you are probably going to want
to specify things like the OU that each account should be created in.

/Al


george

unread,
Apr 19, 2005, 6:47:47 AM4/19/05
to

"Al Dunbar [MS-MVP]" <alan-no-...@hotmail.com> wrote in message
news:%23%23JeNgIR...@TK2MSFTNGP09.phx.gbl...

Well, I thought of suggesting that one, but given the OP's stated initial
information, CSVDE won't let you specify a password upon input, whereas
DSADD does.

Besides, all the DSxxx commands are less 'error-prone' because the input is
parameter-based (like -fn <first name> -ln <last name> -pwd <password>),
compared to the 'positional field'-approach of CSVDE.
What's more, CSVDE does not allow you to 'modify' if you happen to have made
a mistake upon input, whereas the DS-commands (DSMOD) will.

:-))

george


freakadmin

unread,
Apr 19, 2005, 11:59:04 AM4/19/05
to
I wrote this script that uses an excel spreadsheet, I still need to add some
error checking for existing users and changing logon hours, I removed my
company info such as domain name and such so you'll have to replace those,
the excel spreadsheet uses the following fields for the columns
y = firast name
x=last name
u=OU
V=Description
Z=logon script
w=server name
q location
t mailbox store
r=store
s=exchange server
These need to be sequential in the spreadsheet columns

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open
("\\Domain_server\Installs$\New_Users\New_users.xls")
intRow = 2
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2
Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25
Do Until objExcel.Cells(intRow,1).Value = ""
y = objExcel.Cells(intRow, 1).Value
x = objExcel.Cells(intRow, 2).Value
u = objExcel.Cells(intRow, 3).Value
v = objExcel.Cells(intRow, 4).Value
z = objExcel.Cells(intRow, 5).Value
w = objExcel.Cells(intRow, 6).Value
q = objExcel.Cells(intRow, 7).Value
intRow = intRow + 1


Set objOU = GetObject("LDAP://ou=" & u & ",dc=domain,dc=com")
Set objUser = objOU.Create("User", "cn=" & y & "." & x)
objUser.Put "sAMAccountName", y & "." & x
objUser.SetInfo
Set objusers = GetObject("LDAP://cn=" & y & "." & x & ",ou=" & u &
",dc=Domain,dc=com")
objusers.SetPassword "defaultpassword"
objusers.Put "pwdLastSet", 0
objusers.Setinfo

intUAC = objUsers.Get("userAccountControl")
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
objUsers.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
objusers.Setinfo
End If
objUsers.Put "givenName", y
objUsers.Put "sn", x
objUsers.Put "displayName", y & " " & x
objUsers.Put "mail", y & "." & x & "@Domain.com"
objUsers.Put "UserPrincipalName", y & "." & x & "@Domain.com"

objUsers.Put "Description", v

objUsers.Put "physicalDeliveryOfficeName", w

objUsers.Put "scriptPath", z
objUsers.Put "homeDrive", "G:"
objUsers.Put "homeDirectory", "\\" & w & "\" & y & "." & x & "$"
objusers.SetInfo
If q = "Location1" Then
r = " (Mailbox store1)"
ElseIf q = "Location2" Then
r = " (Mailbox store2)"
Else r = ""
End If

If q = "JLocation1" Then
t = "Mailbox Store"
ElseIf q = "Location2" Then
t = "Mailbox Store"
Else t = "Branch Users"
End If

If q = "Jericho" Then
s = "exchangeserver2"
ElseIf q = "location2" Then
s = "exchangeserver1"
Else s = "exchangeserver1"
End If
Dim oIADSUser
Dim oMailbox
Set oIADS = GetObject("LDAP://RootDSE")
'strDefaultNC = oIADS.Get("defaultnamingcontext")

Set oIADSUser = GetObject("LDAP://CN=" & y & "." & x & ",ou=" & u & "," &
"DC=Domain,DC=COM")


Set oMailBox = oIADSUser
Set oIADS = GetObject("LDAP://RootDSE")

oMailBox.CreateMailbox _
"LDAP://" & _
"CN=" & t & r & _
",CN=" & "First Storage Group" & ",CN=InformationStore" & _
",CN=" & s & ", CN=Servers" & _
",CN=Mail, CN=Administrative Groups" & _
",CN=" & "Microsoft Exchange" & ",CN=Microsoft Exchange,CN=Services" & _
",CN=Configuration,DC=Domain,DC=COM"

oIADSUser.SetInfo

ParentFolder = "\\" & w & "\users$\"
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.NameSpace(ParentFolder)
objFolder.NewFolder y & "." & x & "$"

strComputer = W
Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")

Set objNewShare = objWMIService.Get("Win32_Share")

errReturn = objNewShare.Create ("d:\users\" & y & "." & x & "$", y & "." &
x & "$", FILE_SHARE, MAXIMUM_CONNECTIONS, v)
Loop
objExcel.Quit

USER_FILE = "\\Server\Installs$\New_Users\New_users.xls"
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "ITHeldesk"
objEmail.To = "serverinfoDomain.com"
objEmail.Subject = "Users Created"
objEmail.Textbody = "The attached spreadsheet contains a list of users that
have just been created"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"emailserver"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.AddAttachment USER_FILE
objEmail.Configuration.Fields.Update
objEmail.Send

Torgeir Bakken (MVP)

unread,
Apr 21, 2005, 12:48:58 PM4/21/05
to
Tharaka wrote:

> I need to create user accounts for a large number of users. If
> I have an exel file containing username,logon name,password in
> 3 columns how do I read them using an script.
Hi,

See the "Create Users" script here for a script that uses Excel
to create users:

http://www.rlmueller.net/freecode4.htm


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

0 new messages