[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Mass account users creation + mailbox

Posted on 2016-10-02
4
Medium Priority
?
61 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 17

Accepted Solution

by:
Todd Nelson earned 2000 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 17

Assisted Solution

by:Todd Nelson
Todd Nelson earned 2000 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 17

Expert Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 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