RSS
 

Posts Tagged ‘Powersheel’

Bulk import Active Directory Users and Create Email address

01 Jul

I was tasked at work to come up with a way to import new Active Directory accounts and Exchange 2007 email boxes.  I decided to use the Exchange 2007 Management Console which uses lots of powershell.

Here is what I came up with:

This command is used to import users from a CSV file into Exchange 2007 creating email boxes and user accounts.  User accounts are set to change password upon first log in.

Created 20090630, By Mario Leal

NOTES:

  • Command must be copied and pasted into the Exchange Management Console.
  • You must edit “C:\CSV\users.csv” to be the the location of your CSV file.
  • The CSV file must not have an empty line at the end of the file.
  • Duplicates will error, you must watch screen to catch them.
  • Empty middle initial in CSV needs one ” to represent blank.
  • Output file (output.txt) will give a list of successful imports.

Schema (first Line) used for CSV file with an example (second line):
alias,Name,UPN,password,givenName,surname,middleI
maleal,”Mario Leal”,email@address.whatever,somepassword,Mario,Leal,A

Reference URLs:

http://social.technet.microsoft.com/Forums/en-US/exchangesvradmin/thread/2582c672-cddb-4446-9329-889139ebb346
http://www.exchangepedia.com/blog/2006/11/exchange-server-2007-bulk-creation-of.html
http://exchangepedia.com/blog/2006/12/bulk-mailbox-enabling-users-exchange-shell.html

—commandstart—
Import-CSV c:\CSV\users.csv | foreach {

$secureString = ConvertTo-SecureString -string $_.password -AsPlainText –Force

new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -FirstName $_.givenName -LastName $_.surname -Initials $_.middleI -database “Students” -org TEST -Password $securestring -ResetPasswordOnNextLogon $true

} | out-file -filepath “c:\CSV\Output.txt”
—commandend—

Related Links: