Solved

Script to create bulk email accounts

Posted on 2013-01-11
8
1,365 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
This video discusses moving either the default database or any database to a new volume.

730 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