Solved

Mass account users creation + mailbox

Posted on 2016-10-02
4
38 Views
Last Modified: 2016-10-22
Good evening everybody,

Is there any powershell expert who could help me to build a powershell script based on excel file (attached) in order to create user accounts and mailboxes.

Some basic rules are :
samacountname < 20 characters : 8 first from first name "." 10 first characters from last name without spaces

AD account has to be activated at the end of the script.
Please find attached an example of excel file.

Regards,

Julien
ADUsers.xlsx
0
Comment
Question by:Julien R
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
Todd Nelson earned 500 total points (awarded by participants)
ID: 41825771
I'm going to assume a couple of things.  You will...

  1. Be providing the proper naming rules in the CSV file based on your requirements;
  2. Remove the spaces from the headers;
  3. Convert (or save) the Excel file as a CSV file; and
  4. Be running the command from the Exchange server with the RSAT-ADDS feature installed.

This is what I feel the CSV file should look like.  Notice I removed the password column and changed the OU path syntax.  The passwords, IMO, should be passed inline as a secure string instead of in clear text (which typically will not work anyway).

FirstName,LastName,DisplayName,SamAccountName,UPN,ADOUPath,MemberOf1,MemberOf2,MemberOf3,MailboxDatabase,Alias
Jake,IRVIN,FSOCIETY User1,jake.irvin,jake.irvin@fs01.com,"FSOCIETY.COM/Users",Printers_all,dist_list_all,dist_list_fsociety,DATABASE_1,jake.irvin

Open in new window


Assuming those things, this should get you in the right direction...

Run this command, and enter a password when prompted...

$MyPassword = Read-Host "Enter Password:" -AsSecureString

Open in new window


Run this script to create users with mailboxes, and then add them to groups...

Import-Csv "C:\ADUsers.csv" | ForEach-Object { 
     
     New-Mailbox -UserPrincipalName $_.UPN -Alias $_.Alias -saMAccountName $_.SamAccountName -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName -OrganizationalUnit $_.ADOUPath -Database $_.MailboxDatabase -Password $MyPassword -ResetPasswordOnNextLogon $true 
     
     Add-DistributionGroupMember -Identity $_.MemberOf1 -Member $_.Alias -BypassSecurityGroupManagerCheck
     
     Add-DistributionGroupMember -Identity $_.MemberOf2 -Member $_.Alias -BypassSecurityGroupManagerCheck
     
     Add-DistributionGroupMember -Identity $_.MemberOf3 -Member $_.Alias -BypassSecurityGroupManagerCheck
     
}

Open in new window


Hope that helps.
1
 

Author Comment

by:Julien R
ID: 41825824
Thanks for your reply, I will try that solution today at work !
0
 
LVL 14

Assisted Solution

by:Todd Nelson
Todd Nelson earned 500 total points (awarded by participants)
ID: 41826295
I wasn't near my lab yesterday and needed to test the script I provided to ensure I gave you something that worked.  After testing this morning, there is one slight modification that had to be made.  New-Mailbox requires the Name parameter.  The values for the name parameter come from the DisplayName column.  Also, the associated AD user created will be prompted to update their password at first logon.  The new script is below...

$MyPassword = Read-Host "Enter Password" -AsSecureString

Import-Csv "C:\Scripts\MyNewUsers.csv" | ForEach-Object { 
     
     New-Mailbox -Name $_.DisplayName -UserPrincipalName $_.UPN -Alias $_.Alias -saMAccountName $_.SamAccountName -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName -OrganizationalUnit $_.ADOUPath -Database $_.MailboxDatabase -Password $MyPassword -ResetPasswordOnNextLogon $true 
     
     Add-DistributionGroupMember -Identity $_.MemberOf1 -Member $_.Alias -BypassSecurityGroupManagerCheck
     
     Add-DistributionGroupMember -Identity $_.MemberOf2 -Member $_.Alias -BypassSecurityGroupManagerCheck
     
     Add-DistributionGroupMember -Identity $_.MemberOf3 -Member $_.Alias -BypassSecurityGroupManagerCheck
     
}

Open in new window

0
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41855074
Sufficient information to answer request.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
The viewer will learn how to dynamically set the form action using jQuery.
This video discusses moving either the default database or any database to a new volume.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now