Solved

Mass account users creation + mailbox

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple SSL on Exchange 2010 3 28
outlook 6 40
Azure Active Directory Connect change from domain.local to domain.com 1 28
exchange, activesync 2 10
Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to count occurrences of each item in an array.
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…

803 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