Solved

Script to create bulk email accounts

Posted on 2013-01-11
8
1,444 Views
Last Modified: 2013-02-01
We're beginning a program at my work where we're deploying a bunch of iPads.  Each iPad needs an associated email box so I'd like to know if anyone has a script that will read a .CSV file and create a mailbox with the information provided in that .CSV file. ("bulk" mailbox creation)
0
Comment
Question by:skbarnard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 38768912
Try This..
Import-CSV C:\test.csv | ForEach-Object { New-Mailbox -Lastname $_.LastName -Name $_.Name -FirstName $_.FirstName -Organization "test.com/Admin Purpose" -Database "DB001" -UserPrincipalName $_.UserPrincipalName -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}

Open in new window

CSV format
Lastname,Firstname,Name,UserPrincipalName,Password
Test,User,TestUser,TestUser@test.com,P@ssw0rd

Open in new window

0
 

Author Comment

by:skbarnard
ID: 38778871
I keep getting an error that the fields have null values.  I've removed a couple of fields that were throwing the error knowing I can go to the account once it's created and add them back in but then one of the other fields becomes problematic (null or empty string)
I've removed all the fields I possibly can from the CSV file and still receive the attached error.
BulkMailboxError.pdf
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38779685
Can you post the script and input .csv file which you are using?
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:skbarnard
ID: 38779847
It's basically a tweak from what you provided above.  Does the order matter?  I created the csv file in this order Name, First, Last, Alias, UserPrincipal, Organization, Database, Password.
I received errors first on the Name field (the name has a space in it) so I just took that field out of the csv and out of the script.
I also took the Database and Organization fields out of the csv and hard-coded them in the script and completely removed Alias.
The remaining fields in the csv file are First, Last, UserPrincipal and Password.
I've included the code as I used it
Import-CSV C:\temp\Last-Hope-iPad-Accounts.csv | ForEach-Object { New-Mailbox -FirstName $._FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -Organization "iPad User Accounts" -Database DB9 -Password $_.password -AsPlainText -Force }
(it also threw an error when I had the "ConvertTo-SecureString" so I removed that as well)
As a final try, I removed the -AsPlainText -Force from the script and it complains that the UserPrincipalName is an empty string (see the attached file from my last post)
That same error is thrown each time I remove a field from the csv and script.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38779897
Order doesn't matter but if you are using following header for CSV file the script also should change based on headers..
Name, First, Last, Alias, UserPrincipal, Organization, Database, Password
It should be like..
Import-CSV C:\temp\Last-Hope-iPad-Accounts.csv | ForEach-Object { New-Mailbox -FirstName $._First -LastName $_.Last -UserPrincipalName $_.UserPrincipal -Organization "iPad User Accounts" -Database $_.Database -Password (ConvertTo-SecureString $_.Password -AsPlainText -Force)}

Open in new window

If you still have issue please post the csv file which you are using. I think something is wrong with the file format..
0
 

Author Comment

by:skbarnard
ID: 38828699
I ended up creating all the accounts "manually" - there weren't that many left when I posted this question.
However, it would be nice to know what I did wrong so I've attached the CSV file I was attempting to use.
I had no header row in this file - can't remember why it was left off.  The format is:
first name, last name, alias, userprincipalname, password.
Last-Hope-iPad-Accounts.csv
0
 
LVL 40

Accepted Solution

by:
Subsun earned 300 total points
ID: 38829815
If your CSV file don’t have a header then Import-csv will consider the first line of CSV file as a header, and script will fail..

You can also specify the header in script by adding Header  parameter to Import-CSV command.. for example..

Import-CSV C:\temp\Last-Hope-iPad-Accounts.csv -Header firstname,lastname,alias,userprincipalname,password | ForEach-Object { New-Mailbox -FirstName $._First -LastName $_.Last -UserPrincipalName $_.userprincipalname -Organization "iPad User Accounts" -Database $_.Database -Password (ConvertTo-SecureString $_.Password -AsPlainText -Force)}

Open in new window

0
 

Author Closing Comment

by:skbarnard
ID: 38844886
While I haven't had a chance to retry this script, not having a header on the import csv file is likely what caused the script not to work.
I am keeping a copy of this script for the next time I have many accounts to create.
Thanks Subsun!
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read this checklist to learn more about the 15 things you should never include in an email signature.
Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question