Solved

Mass account users creation + mailbox

Posted on 2016-10-02
4
37 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

708 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