Exchange Online Shared Mailbox Bulk Create

Dominik Dudczak 176 Reputation points
2021-02-16T13:41:29.33+00:00

Hi Everyone,

I am currently trying to setup shared mailboxes for an organisation. As it is a Pain in the A** to create them inside the portal one by one (especially if we are talking about ~ 100 Mailboxes). I tried to realize that via Powershell and a CSV file. This is what i got so far:

Import-Csv "C:\Users\Example\Documents\Mailboxes.csv" | foreach-object {​​​​ New-Mailbox -Name $.MyName -DisplayName $.MyDisplay -Shared }

And this is the Format of the according csv File:

MyName,MyDisplay

test,test

test1,test1

So far so good, it creates the Mailboxes out of the CSV file without any Issues. Now I need to assign mailbox permissions for those mailboxes. Sure I could do that with a new CSV File in the same way again:

Import-Csv "C:\Users\Example\Documents\Access" | foreach-object { Add-MailboxPermission $.Mailbox -User $.User -AccessRights $_.Access }

With the according CSV File again:

Mailbox,User,AccessRights

test,user@keyman ,FullAccess

test,user2@keyman ,FullAccess

test1,user2@keyman ,FullAccess

This way I can already save some time but I still have to created the two CSV files and depending on how many user have permissions to the same mailbox, the CSV file gets rather long and repetitive.

My Questions now are:

  1. Is there a way to create the mailboxes and assign the permissions in the same step using only one csv file?
  2. Am I taking the wrong approach and is there a better one than working with CSV files ?
  3. If yes please explain other possibilities I have to achieve my goal.
  4. Is there a way to pass an array to the powershell command (for the parameter -User for example) ?

Looking forward to your inputs and thoughts on this.

Thank you in advance :)

Dominik

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,271 Reputation points
    2021-02-17T02:34:48.18+00:00

    anonymous user

    The "-User" doesn't accept array, so you need to add permission one by one:
    68863-qa-kyle-10-01-35.png

    If you want to use one CSV file as source file, you need to change it into this format:
    68873-qa-kyle-10-32-26.png

    The you could use script below to create shared mailbox and add permission:

    $Datas  = import-csv d:/temp/shared.csv  
      
    foreach($Data in $Datas){  
        if((Get-Mailbox $data.name -erroraction 'silentlycontinue') -eq $null){  
            New-Mailbox -Name $data.Name -DisplayName $data.DisplayName -Shared  
        }  
        Add-MailboxPermission -Identity $data.Name -User $data.User -AccessRights $data.AccessRights  
    }  
    

    68894-qa-kyle-10-32-01.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.