Solved

Mass account users creation + mailbox

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

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 15

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 15

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 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