How to Create Common Types of Microsoft 365 Mailboxes Using PowerShell

August 29, 2023
6 min read

One of the advantages of using Microsoft 365 is having access to professional mailboxes that your users can access from any device. Apart from the regular user-based mailbox, you can use Windows PowerShell to create different types of mailboxes that help you manage your organization’s emails efficiently. In this article, I explain some of the important mailboxes in Microsoft 365 and how to create them.

For those who like to watch and learn, check out the 3-minute video at the end of this article, which is a shortened version of this content.

Prerequisites

You should know how to connect to Microsoft Online (MSOL) Service and Microsoft 365 Exchange Online using PowerShell.

User Mailboxes

These are mailboxes that belong to your Microsoft 365 users. They get created when you create your Microsoft 365 users and are assigned to them by default for their personal use. As an administrator, however, you still have access to these user mailboxes and all the data they contain.

To create the user and the user mailbox, run the following command, as shown in Figure 1:

New-MsolUser -DisplayName "Jane Doe" -UserPrincipalName "janedoe@acerscorp.onmicrosoft.com" 
-UsageLocation IN -LicenseAssignment acerscorp:O365_BUSINESS_PREMIUM  

This screenshot shows how you can use the new msoluser cmdlet to create a Microsoft 365 user mailbox.
Figure 1: Using the New-MsolUser cmdlet for creating a user mailbox. | Used with permission from Microsoft.

How Does the Script Work?

Let’s break down the script:

  1. Use the New-MsolUser cmdlet to create the new user.
  2. Pass in the -DisplayName, -UserPrincipalName, -UsageLocation, and -LicenseAssignment parameter values respectively.

Note: Remember to pass your country code to the -UsageLocation parameter. Also, replace acerscorp:O365_BUSINESS_PREMIUM with your Microsoft 365 license information. If you don’t know your license details, run the Get-MsolAccountSku command, as shown in Figure 2.

This screenshot shows how you can use the get msolaccountsku cmdlet to get your Microsoft 365 license info.
Figure 2: Running the Get-MsolAccountSku cmdlet to get your license info. | Used with permission from Microsoft.

Shared Mailboxes

These are mailboxes shared among a group of users belonging to the same department (like admin, support, or legal) that helps them send emails to and receive emails from outsiders. Unlike the Microsoft 365 user mailboxes, shared mailboxes don’t require a username/password to sign in, and administrators grant access on a user permission basis.

To create a shared mailbox using PowerShell, run the following command, as shown in Figure 3: 

New-Mailbox -Shared -Name "Marketing Department" -DisplayName "Marketing" -Alias marketing

This screenshot shows how you can use the new mailbox cmdlet to create a Microsoft 365 shared mailbox.
Figure 3: Using the New-Mailbox cmdlet to create a shared mailbox. | Used with permission from Microsoft.

How Does the Script Work?

Let’s break down the script:

  1. Use the New-Mailbox cmdlet. Pass in the -Shared parameter to indicate the mailbox is going to be a shared mailbox.
  2. Pass in the -Name, -DisplayName, and -Alias parameter values as "Marketing Department", Marketing, and marketing respectively.

Microsoft 365 Group Mailboxes

These mailboxes are created when you create Microsoft 365 groups that enable your users to work together through emails, conversations, and sharing files. Just like shared mailboxes, Microsoft 365 group mailboxes serve as a single point of contact for a team or group of users.

To create a Microsoft 365 group and its mailbox, run the following command, as shown in Figure 4:

New-UnifiedGroup -DisplayName "Test Group" -PrimarySmtpAddress "testgroup@acerscorp.onmicrosoft.com"

This screenshot shows how you can use the new unified group cmdlet to create a Microsoft 365 group and its mailbox.
Figure 4: Using the New-UnifiedGroup cmdlet for creating a Microsoft 365 group and its mailbox. | Used with permission from Microsoft.

How Does the Script Work?

Let’s break down the script:

  1. Use the New-UnifiedGroup cmdlet.
  2. Pass in the -Displayname and -PrimarySmtpAddress parameter values as "Test Group" and "testgroup@acerscorp.onmicrosoft.com" respectively.

Group Mailboxes Versus Shared Mailboxes

While both group mailboxes and shared mailboxes unite users for a common purpose, what sets Microsoft 365 group mailboxes apart are the following points:

  • Group mailboxes integrate with SharePoint sites by default, while shared mailboxes are not.
  • They can be integrated with Microsoft Teams, whereas shared mailboxes cannot.
  • They allow members to receive a copy of the emails sent to the group in their own user mailbox, while shared mailboxes do not.

Note: You can also create ‘teams-enabled’ Microsoft 365 groups so that your Microsoft 365 group’s users can have their conversations and share their work using Microsoft Teams. 

Distribution Group Mailboxes

These are mailboxes associated with the Microsoft 365 distribution groups you create. If your objective is only to send email notifications to a group of people, the distribution group is your best choice. Distribution groups unite users under a common mailbox and help you send email notifications to them.

To create a Microsoft 365 distribution group and its mailbox, run the following command, as shown in Figure 5. 

New-DistributionGroup -Name "TestDistributionGroup" -PrimarySmtpAddress 
"testdistributiongroup@acerscorp.onmicrosoft.com"  

This screenshot shows how you can use the new distribution group cmdlet to create a Microsoft 365 distribution group and its mailbox.
Figure 5: Using the New-DistributionGroup cmdlet for creating a Microsoft 365 group and its mailbox. | Used with permission from Microsoft.

How Does the Script Work?

Let’s break down the script:

  1. Use of the New- DistributionGroup cmdlet.
  2. Pass in the -Name and -PrimarySmtpAddress parameter values as “TestDistributionGroup” and “testdistributiongroup@acerscorp.onmicrosoft.com” respectively.

Possible Errors You Might Face

Here are some possible errors you might face and ways to rectify them:

  • Not running your shell as Administrator: Select the PowerShell program from the Windows start menu, and then choose the Run as Administrator option, as shown in Figure 6.
This screenshot shows how you can run your Windows PowerShell console in administrator mode.
Figure 6: Running PowerShell as Administrator. | Used with permission from Microsoft.
  • Execution Policy set to restricted mode: Execution policy setting determines the script execution rights for the current user. If you are signing in for the first time, chances are this is set to restricted mode. Therefore, ensure the execution policy is set to RemoteSigned (which allows you to run your scripts). The command for doing so is the following: Set-ExecutionPolicy RemoteSigned

Note: To check your current script execution rights, run the Get-ExecutionPolicy command.  

  • Typos in your PowerShell script: You can run into typos even while copying/pasting scripts. It’s best to save your scripts in separate .ps1 files and run them. This not only saves time but also prevents your script from running into unnecessary errors.

Conclusion

Now that you know the different mailboxes that Microsoft 365 offers, in the next article I’ll focus in more depth on how you can create shared mailboxes using the following:

  • The Microsoft 365 admin center
  • The Microsoft 365 Exchange admin center (EAC)
  • PowerShell, since the shared mailbox is one of the most widely used mailbox types among organizations

For Those Who Like to Watch and Learn

The following video is a shortened (3-minute) version of this article. It shows you how to use PowerShell to create different types of mailboxes that help you manage your organization’s emails efficiently.

Thilak Kumar Singh

Thilak Kumar Singh

Thilak Kumar Singh is a trainer who believes in teaching about IT in the simplest possible way with more emphasis on visual mode of learning. He firmly believes in democratizing IT knowledge, especially of Microsoft solutions, in which he specializes as a trainer and consultant.

He observes that in this era dominated by cloud computing and collaboration, where IT has reached users unimaginable hitherto, IT knowledge must not be an obscure science, but rather be available to anyone who wishes to engage with IT.