question

DominikDudczak-5294 avatar image
0 Votes"
DominikDudczak-5294 asked ·

Exchange Online Shared Mailbox Bulk Create

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@domain,FullAccess

test,user2@domain,FullAccess

test1,user2@domain,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

office-exchange-online-itpro
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KyleXu-MSFT avatar image
1 Vote"
KyleXu-MSFT answered ·

@DominikDudczak-5294

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.


· 4 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KyleXu-MSFT

Thanks for the Answer.

This solves my problem of having to create two CSV files separately. Howerver I still have to create multiple lines for the same Mailbox inside the CSV, which is still not perfect from my point of view. Let's say, I have 10 Mailboxes and for each Mailbox I have to add permissions for 20 users. At the end I will have a CSV File of 200 Lines.


Ideally I would like to use one line only per Mailbox to keep the manual work as low as possible. (Maybe I'm asking for too much but there has to be a solution for that).

For now I will try out your script and expand it with the possibility to add "send as" rights for a user.

Once I find a way to improve the script, I will make sure to post the solution here.


Regards
Dominik

0 Votes 0 ·
KyleXu-MSFT avatar image KyleXu-MSFT DominikDudczak-5294 ·

The logic of the human brain is not the same as that of a computer. If we want to use a script to do a certain operation, we need to use the computer's logic to write the script. Otherwise, the computer does not know how to parse the data.

0 Votes 0 ·
KyleXu-MSFT avatar image KyleXu-MSFT KyleXu-MSFT ·

@DominikDudczak-5294

I am writing here to confirm with you any update about this thread now?
If the above suggestion helps, please be free to mark it as an answer for helping more people.

0 Votes 0 ·
Show more comments