Управление почтовым ящиком пользователя с помощью power shell

Get-Mailbox Report

Let’s begin with the simplest of all commands: Get-Mailbox. This helps you view all the mailboxes available in your Microsoft 365 tenant, as shown in Figure 1.

This screenshot shows how you can generate Microsoft 365 exchange online mailbox reports using get-mailbox cmdlet.
Figure 1: Running the Get-Mailbox cmdlet to fetch all mailboxes | Used with permission from Microsoft. View Full Size
This screenshot shows how you can generate Microsoft 365 Exchange Online mailbox reports of a specific mailbox type using get-mailbox cmdlet.
Figure 2: Modifying the Get-Mailbox cmdlet to fetch only user mailboxes. | Used with permission from Microsoft. View Full Size

You can also fetch the details of individual mailboxes by specifying the mailbox alias, such as get-mailbox support as shown in Figure 3.

This screenshot shows how you can get the details of an individual mailbox using the get-mailbox cmdlet.
Figure 3: Modifying the Get-Mailbox cmdlet to fetch a specific mailbox. | Used with permission from Microsoft. View Full Size

Connect to Exchange Online PowerShell

To be able to run PowerShell commands, you must Connect to Exchange Online PowerShell.

Connect-ExchangeOnline

Sign in to your account and enter the password.

Mail Forwarding–Enabled Mailbox Reports

You should get a response similar to Figure 7.

This screenshot shows how you can generate mail forwarding-enabled mailbox reports using the get-mailbox cmdlet.
Figure 7: Using the Get-Mailbox cmdlet to fetch all the mailboxes that forward mail. | Used with permission from Microsoft. View Full Size

How Does the Script Work?

  1. To get information about all your Microsoft 365 mailboxes, use the Get-Mailbox -ResultSize Unlimited command.
  2. Query for only those Microsoft 365 user accounts that have the FowardingAddress property configured for them.
  3. Display the DisplayName and the ForwardingAddress properties from the fetched results.

Wrapping up

How can I assign full access permissions for a mailbox in Office 365 using PowerShell?

How do I assign mailbox permissions with Exchange Online PowerShell?

How do I add permissions to an on-premises mailbox for an Office 365 recipient?

How to Grant Admin Access to All Mailboxes in Office 365?

  1. Open PowerShell as an administrator and connect to Office 365 using the “Connect-ExchangeOnline” cmdlet.
  2. Run the “Get-Mailbox” cmdlet to retrieve a list of all mailboxes in your organization.
  3. Use a “ForEach” loop to iterate through each mailbox and grant admin access to the user or group you want to give access to.
  4. Use the “Add-MailboxPermission” cmdlet to grant admin access to the mailbox.
  5. Specify the access rights you want to grant, such as “FullAccess”

PowerShell Script to Grant Full Access to All Mailboxes

#User to grant Mailbox access
$UserID = "steve@crescent.com"
#Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName Admin@Crescent.com
#Get All Mailboxes
$Mailboxes = Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') }
#Grant Full Access to Each User Mailbox
$Mailboxes | ForEach-Object { #Add Mailbox Access Add-MailboxPermission -Identity $_.Alias -User $UserID -AccessRights fullaccess -InheritanceType all -AutoMapping:$true | Out-Null #Output Message Write-host -f Green "Access has been granted to:"$_.UserPrincipalName
}

Table of contents

  • PowerShell to Add Mailbox Permissions in Office 365
  • How to Add Mailbox permissions using PowerShell?
  • How to Grant Admin Access to All Mailboxes in Office 365?
  • Wrapping up

Convert user mailbox

Convert user mailbox to shared mailbox

Get-Mailbox "KellyTest" | Set-Mailbox -Type Shared

Convert user mailbox to room mailbox

Get-Mailbox "KellyTest" | Set-Mailbox -Type Room

Convert user mailbox to equipment mailbox

Get-Mailbox "KellyTest" | Set-Mailbox -Type Equipment

Display information user mailbox

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailBox")' | Select Name,Alias

The PowerShell output looks like the below example.

PS C:\> Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailBox")' | Select Name,Alias
Name Alias
---- -----
ea2b7e6a-fb01-42e3-9fb8-ccf13a5f2e67 Stephen.Hunter
d912b0fc-6f7e-4ec2-a9e4-854ed27a511a Brenda.Smith
eec2668a-0773-4947-93ba-2223f6acfe55 David.Kent
fd199cb4-2ebf-4171-96e2-12fd75453e39 Susan.Brown
fa956d8c-87df-4cd4-ac2a-ac1f3d7cac8b Chris.Lucas
d89be5ce-6495-4009-b61b-81126c239c34 George.Wilson
a9532b30-4edb-4b66-a3b0-6ac972a6065b Jill.Bates
b602b148-2fcf-435a-9d34-ce72c3a8c748 Diana.Baker
3bb176aa-d0ba-47f7-aecc-f4837593006e Mary.James
41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5 Amanda.Hansen
KellyTest Kelly1 

Export list of licensed user mailboxes to CSV file

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select-Object DisplayName,Alias,RecipientTypeDetails,PrimarySmtpAddress | Export-CSV "C:\temp\User Mailboxes Info.CSV" –NoTypeInformation -Encoding UTF8

Once you export the information, you can find the CSV file in the C:\temp folder.

Open the CSV file with an application like Microsoft Excel to see the results.

Display user mailbox information permissions

Display information about Full Access and Send As permission:

  1. The PowerShell cmdlet Get-MailboxPermission shows Full Access permission
  2. The PowerShell cmdlet Get-RecipientPermission shows Send As permission

The default output of both these PowerShell commands shows redundant information, making it difficult to understand the Exchange mailbox permissions clearly. For this reason, we will filter and remove redundant information.

Get-MailboxPermission "Brenda Smith" | Where-Object { ($_.IsInherited -eq $False) -and -not ($_.User -like "NT AUTHORITY\SELF") } | Select-Object Identity, User, AccessRights
PS C:\> Get-MailboxPermission "Brenda Smith" | Where-Object { ($_.IsInherited -eq $False) -and -not ($_.User -like "NT AUTHORITY\SELF") } | Select-Object Identity, User, AccessRights
Identity User AccessRights
-------- ---- ------------
d912b0fc-6f7e-4ec2-a9e4-854ed27a511a David.Kent@m365info.com {FullAccess}
Get-RecipientPermission "Brenda Smith" | Where-Object {($_.IsInherited -eq $False) -and -not ($_.Trustee -like "NT AUTHORITY\SELF") } | Select-Object Trustee, AccessRights
PS C:\> Get-RecipientPermission "Brenda Smith" | Where-Object {($_.IsInherited -eq $False) -and -not ($_.Trustee -like "NT AUTHORITY\SELF") } | Select-Object Trustee, AccessRights
Trustee AccessRights
------- ------------
Brenda.Smith@m365info.com {SendAs}
Amanda.Hansen@m365info.com {SendAs}
KellyTest@m365info.com {SendAs} 

What is Enable-RemoteMailbox in PowerShell?

Each of these syntax elements and parameters has a specific meaning:

  • Identity: Specifies the user account for which you want to enable the remote mailbox. The <UserIdParameter> can be the user’s alias, user principal name (UPN), distinguished name (DN), or other identifier;
  • RemoteRoutingAddress: Specifies the email address to be used as the remote routing address for the mailbox. This is typically an external email address that is associated with the user’s mailbox in the remote Exchange environment;
  • ACLableSyncedObjectEnabled: This switch parameter enables ACLable synced objects. It is used in scenarios where Access Control Lists (ACLs) are applicable to synchronized objects;
  • Alias: Specifies the alias for the mailbox. The alias is a unique identifier for the mailbox within the Exchange environment;
  • Confirm: This switch parameter prompts you for confirmation before executing the command.
  • DisplayName: Specifies the display name for the mailbox. The display name is the name that is shown in the address book and other user interfaces;
  • DomainController: Specifies the fully qualified domain name (FQDN) of the domain controller that the cmdlet should connect to for its operation. This parameter is optional;
  • PrimarySmtpAddress: Specifies the primary SMTP address for the mailbox. This is the main email address associated with the user’s mailbox.

Use Filter parameter with Get-Mailbox in PowerShell

You can change the PowerShell display output using the -Filter parameter with the Get-Mailbox cmdlet. It helps you to find a specific mailbox without knowing the exact name.

Get list of user mailboxes

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' -ResultSize Unlimited | Select-Object Identity, UserPrincipalName, Alias

Get list of shared mailboxes

Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' -ResultSize Unlimited | Select-Object Identity, UserPrincipalName, Alias

Get list of room mailboxes

Run the below PowerShell command to show all room mailboxes.

Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailbox")' -ResultSize Unlimited | Select-Object Identity, UserPrincipalName, Alias

Get list of equipment mailboxes

Run the below PowerShell command to show all equipment mailboxes.

Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' -ResultSize Unlimited | Select-Object Identity, UserPrincipalName, Alias

Find mailbox with wildcard

In our example, we want to find all the mailboxes with the letters “al” in their name. You need to use a wildcard to find the string values.

Note: Not all the properties accept the wildcard asterisk (*). See the entire list of filterable properties in Exchange Online PowerShell.

  • Use an asterisk (*) before and after the letters

Run the below PowerShell command.

Get-Mailbox -ResultSize Unlimited -Filter {Alias -like '*al*'} | Format-Table -AutoSize

The PowerShell result is shown below.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
Catch All Catch.All EURPR02DG588-db346 49.5 GB (53,150,220,288 bytes) 182292ee-eaec-438b-bf14-f25dec9cf1cd
12eefbb2-e5f4-4eec-bd18-df7ca2f1ee6b Ken.Walker EURPR02DG393-db032 99 GB (106,300,440,576 bytes) 12eefbb2-e5f4-4eec-bd18-df7ca2f1ee6b
e5c3a5e8-eeae-4829-94dc-fb7228bcf8da Ryan.Walker EURPR02DG514-db387 99 GB (106,300,440,576 bytes) e5c3a5e8-eeae-4829-94dc-fb7228bcf8da

It shows all the mailboxes that include the letters “al” in their Alias.

Option 2: Find mailbox using wildcard at the beginning of string value

Get all the mailboxes that start with the letters “an” in their name.

  • Use an asterisk (*) after the letters

Run the PowerShell command example.

Get-Mailbox -ResultSize Unlimited -Filter "Alias -like 'an*'" | Format-Table -AutoSize

See the PowerShell output result.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
82cd0d62-e974-4892-aca6-e0387abc62be Anna.Bell EURPR02DG037-db046 99 GB (106,300,440,576 bytes) 82cd0d62-e974-4892-aca6-e0387abc62be
5cae3874-442b-459c-8f33-3aee5b879275 Anne.Butler EURPR02DG275-db096 99 GB (106,300,440,576 bytes) 5cae3874-442b-459c-8f33-3aee5b879275

It shows all the mailboxes that start with the letters “an” in their Alias.

Option 3: Find mailbox using wildcard at the end of string value

:/>  Как отключить обновления Windows 10 - 8 рабочих способов

Get all the mailboxes that end with the letters “er” in their name.

  • Use an asterisk (*) before the letters

Run the PowerShell command example.

Get-Mailbox -ResultSize Unlimited -Filter "Alias -like '*er'" | Format-Table -AutoSize

See the PowerShell output result.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
5cae3874-442b-459c-8f33-3aee5b879275 Anne.Butler EURPR02DG275-db096 99 GB (106,300,440,576 bytes) 5cae3874-442b-459c-8f33-3aee5b879275
b602b148-2fcf-435a-9d34-ce72c3a8c748 Diana.Baker EURPR02DG060-db131 99 GB (106,300,440,576 bytes) b602b148-2fcf-435a-9d34-ce72c3a8c748
12eefbb2-e5f4-4eec-bd18-df7ca2f1ee6b Ken.Walker EURPR02DG393-db032 99 GB (106,300,440,576 bytes) 12eefbb2-e5f4-4eec-bd18-df7ca2f1ee6b
e5c3a5e8-eeae-4829-94dc-fb7228bcf8da Ryan.Walker EURPR02DG514-db387 99 GB (106,300,440,576 bytes) e5c3a5e8-eeae-4829-94dc-fb7228bcf8da
c32b2b27-d809-439a-a3e3-eb7a749eeb72 Stephen.Hunter EURPR02DG597-db438 99 GB (106,300,440,576 bytes) c32b2b27-d809-439a-a3e3-eb7a749eeb72

It shows all the mailboxes that end with the letters “er” in their Alias.

Get all inactive mailboxes

You can also check if there are any inactive mailboxes in your organization using the -Filter parameter.

Run the below PowerShell command example.

Get-Mailbox -ResultSize Unlimited -Filter 'IsInactiveMailbox -eq $True' | Format-Table UserPrincipalName, Identity, IsInactiveMailbox

The PowerShell output result.

UserPrincipalName Identity IsInactiveMailbox
----------------- -------- -----------------
Amanda.Morgan@m365info.com 41377e9c-dc47-46c0-b4a5-1d5bbdcb5dd5 True
Carlos.Baker@m365info.com 82cd0d62-e974-4892-aca6-e0387abc63be True
Mike.Shawn@m365info.com 5cae3874-442b-459c-8f33-3aee5b879175 True
Trevor.Smith@m365info.com 0f38d53f-cbe0-4844-86e9-1032a45ba51b True

What Can You Use the Enable-RemoteMailbox Command For?

  1. Mailbox Provisioning: It provisions a mailbox for the specified user account. This involves creating the necessary mailbox objects and attributes in the Exchange environment;
  2. Mailbox Association: It associates the user account in the on-premises Active Directory with the newly created mailbox in the remote Exchange environment. This linkage ensures that the user can access their mailbox seamlessly;
  3. Remote Mailbox Configuration: It configures settings for the mailbox on the remote Exchange server, such as storage quotas, permissions, and other mailbox-related attributes;
  4. Mail Flow Configuration: It sets up mail flow for the user’s mailbox, allowing emails to be sent and received.

Format Get-Mailbox output for all mailboxes

We want to optimize the output displayed by the Get-mailbox command.

There are a few things with problems:

  • Using the Format-Table (ft) displays very limited information, whereas the Format-List (fl) displays too much information, which is not easy to read.
  • The PowerShell console screen has a specific width for each header, which leads to a limited amount of data displayed.

We will show you different solutions to find or filter the mailboxes.

Using the Property option

It will automatically override the default properties displayed by the Get-Mailbox command.

See the PowerShell syntax example.

Get-Mailbox -ResultSize Unlimited | Format-Table -Property Alias, Displayname, EmailAddresses

You can use a shortened version without specifying the -Property option. When you use the option Format-Table, you can use the abbreviation ft, and for Format-List, you can use the abbreviation fl.

Run the below PowerShell command example.

Get-Mailbox -ResultSize Unlimited | Format-Table Alias, Displayname, EmailAddresses

See the PowerShell output results.

Alias DisplayName EmailAddresses
----- ----------- --------------
Amanda.Hansen Amanda Hansen {SIP:amanda.hansen@m365info.com, SPO:SPO_a21d1f73-5b3e-47db-bccd-16559e7d5560@SPO_a2ff010e-0e03-4c56-8863-2ae7f07876dd, SMTP:Amanda.…
Anna.Bell Anna Bell {SIP:anna.bell@m365info.com, SMTP:Anna.Bell@m365info.com, smtp:Anna.Bell@ms365info.onmicrosoft.com}
Anne.Butler Anne Butler {SIP:anne.butler@m365info.com, SMTP:Anne.Butler@m365info.com}
Brenda.Smith Brenda Smith {SIP:brenda.smith@m365info.com, SMTP:Brenda.Smith@m365info.com, smtp:Brenda.Smith@ms365info.onmicrosoft.com}
Brian.Mill Brian Mill {SIP:brian.mill@m365info.com, SMTP:Brian.Mill@m365info.com}
Carl.Hawk Carl Hawk {SIP:carl.hawk@m365info.com, SMTP:Carl.Hawk@m365info.com, smtp:Carl.Hawk@ms365info.onmicrosoft.com}
Catch.All Catch All {smtp:Catch.All@ms365info.onmicrosoft.com, SMTP:Catch.All@m365info.com}
Charles.Mitchel Charles Mitchel {SMTP:Charles.Mitchel@m365info.com, smtp:Charles.MitchelNEW@m365info.com}
Diana.Baker Diana Baker {SMTP:Diana.Baker@m365info.com, SPO:SPO_13fee752-5966-4b62-98e2-f27fe9e5f66d@SPO_a2ff010e-0e03-4c56-8863-2ae7f07876dd}

It shows all the properties you provided, but some values are too long for the limited PowerShell console output width.

A solution to the limited width of the values output could be using the Format-List (fl) with the same PowerShell command.

Run the below PowerShell command example.

Get-Mailbox -ResultSize Unlimited | Format-List Alias, Displayname, EmailAddresses

See the PowerShell output result.

Alias : Amanda.Hansen
DisplayName : Amanda Hansen
EmailAddresses : {SIP:amanda.hansen@m365info.com, SPO:SPO_a21d1f73-5b3e-47db-bccd-16559e7d5560@SPO_a2ff010e-0e03-4c56-8863-2ae7f07876dd, SMTP:Amanda.Hansen@m365info.com}
Alias : Anna.Bell
DisplayName : Anna Bell
EmailAddresses : {SIP:anna.bell@m365info.com, SMTP:Anna.Bell@m365info.com, smtp:Anna.Bell@ms365info.onmicrosoft.com}
Alias : Anne.Butler
DisplayName : Anne Butler
EmailAddresses : {SIP:anne.butler@m365info.com, SMTP:Anne.Butler@m365info.com}
Alias : Brenda.Smith
DisplayName : Brenda Smith
EmailAddresses : {SIP:brenda.smith@m365info.com, SMTP:Brenda.Smith@m365info.com, smtp:Brenda.Smith@ms365info.onmicrosoft.com}
Alias : Brian.Mill
DisplayName : Brian Mill
EmailAddresses : {SIP:brian.mill@m365info.com, SMTP:Brian.Mill@m365info.com}
Alias : Carl.Hawk
DisplayName : Carl Hawk
EmailAddresses : {SIP:carl.hawk@m365info.com, SMTP:Carl.Hawk@m365info.com, smtp:Carl.Hawk@ms365info.onmicrosoft.com}
Alias : Catch.All
DisplayName : Catch All
EmailAddresses : {smtp:Catch.All@ms365info.onmicrosoft.com, SMTP:Catch.All@m365info.com}
Alias : Charles.Mitchel
DisplayName : Charles Mitchel
EmailAddresses : {SMTP:Charles.Mitchel@m365info.com, smtp:Charles.MitchelNEW@m365info.com}
Alias : Diana.Baker
DisplayName : Diana Baker
EmailAddresses : {SMTP:Diana.Baker@m365info.com, SPO:SPO_13fee752-5966-4b62-98e2-f27fe9e5f66d@SPO_a2ff010e-0e03-4c56-8863-2ae7f07876dd}

View mailbox statistics

You can also show the mailbox and folder size information of a single or all mailboxes.

Run the below PowerShell command to show information for a single mailbox.

Get-Mailbox "Amanda.Hansen@m365info.com" | Get-MailboxStatistics | Format-List DisplayName, StorageLimitStatus, TotalItemSize, TotalDeletedItemSize, ItemCount, DeletedItemCount

The PowerShell output shows the mailbox statistics of a single mailbox.

DisplayName : Amanda Hansen
StorageLimitStatus :
TotalItemSize : 28.66 MB (30,056,815 bytes)
TotalDeletedItemSize : 4.378 MB (4,590,806 bytes)
ItemCount : 766
DeletedItemCount : 801

Run the below PowerShell command to show information for all mailbox sizes.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Format-List DisplayName, StorageLimitStatus, TotalItemSize, TotalDeletedItemSize, ItemCount, DeletedItemCount

View mailbox quota size

Run the below PowerShell command to show quotas assigned to a single mailbox.

Get-Mailbox "Amanda.Hansen@m365info.com" | Format-List *Quota

It shows the below PowerShell output.

ProhibitSendQuota : 99 GB (106,300,440,576 bytes)
ProhibitSendReceiveQuota : 100 GB (107,374,182,400 bytes)
RecoverableItemsQuota : 30 GB (32,212,254,720 bytes)
RecoverableItemsWarningQuota : 20 GB (21,474,836,480 bytes)
CalendarLoggingQuota : 6 GB (6,442,450,944 bytes)
IssueWarningQuota : 98 GB (105,226,698,752 bytes)
RulesQuota : 256 KB (262,144 bytes)
ArchiveQuota : 100 GB (107,374,182,400 bytes)
ArchiveWarningQuota : 90 GB (96,636,764,160 bytes)

Run the below PowerShell command to show quotas assigned to all mailboxes.

Get-Mailbox -ResultSize Unlimited | Format-List DisplayName, Alias, *Quota

Using the Wrap option

Another solution to view the long values in the PowerShell output is to use the -Wrap option.

The properties, such as Email addresses that include long values and reach the PowerShell console width limitation will be moved to the next line. In this case, we can see the entire value of the email addresses.

Run the PowerShell command example.

Get-Mailbox -ResultSize Unlimited | Format-Table Alias, Displayname, EmailAddresses -Wrap

See the PowerShell output results.

Alias DisplayName EmailAddresses
----- ----------- --------------
Amanda.Hansen Amanda Hansen {SIP:amanda.hansen@m365info.com, SPO:SPO_a21d1f73-5b3e-47db-bccd-16559e7d5560@SPO_a2ff010e-0e03-4c56-8863-2ae7f07876dd, SMTP:Amanda.Hansen@m365info.com}
Anna.Bell Anna Bell {SIP:anna.bell@m365info.com, SMTP:Anna.Bell@m365info.com, smtp:Anna.Bell@ms365info.onmicrosoft.com}
Anne.Butler Anne Butler {SIP:anne.butler@m365info.com, SMTP:Anne.Butler@m365info.com}
Brenda.Smith Brenda Smith {SIP:brenda.smith@m365info.com, SMTP:Brenda.Smith@m365info.com, smtp:Brenda.Smith@ms365info.onmicrosoft.com}
Brian.Mill Brian Mill {SIP:brian.mill@m365info.com, SMTP:Brian.Mill@m365info.com}
Carl.Hawk Carl Hawk {SIP:carl.hawk@m365info.com, SMTP:Carl.Hawk@m365info.com, smtp:Carl.Hawk@ms365info.onmicrosoft.com}
Catch.All Catch All {smtp:Catch.All@ms365info.onmicrosoft.com, SMTP:Catch.All@m365info.com}
Charles.Mitchel Charles Mitchel {SMTP:Charles.Mitchel@m365info.com, smtp:Charles.MitchelNEW@m365info.com}
Diana.Baker Diana Baker {SMTP:Diana.Baker@m365info.com, SPO:SPO_13fee752-5966-4b62-98e2-f27fe9e5f66d@SPO_a2ff010e-0e03-4c56-8863-2ae7f07876dd}

It shows the rest of the Email Addresses displayed on the next line.

Using the Group option

When we use the Get-Mailbox command, the result includes a list of all the mailbox types, such as:

The Group option enables you to group the output results. When you use the Group option, you must specify the properties that will serve as the source for the grouping.

In our example, we want to group the information according to the mailbox type, so we will use the property RecipientTypeDetails.

Run the PowerShell command example.

Get-Mailbox -ResultSize Unlimited | Group RecipientTypeDetails

The PowerShell output result is shown below.

Count Name Group
----- ---- ----- 1 DiscoveryMailbox {Discovery Search Mailbox} 2 EquipmentMailbox {Projector 21, Projector 8} 1 RoomMailbox {RoomTest8} 2 SharedMailbox {Catch All, Info Box} 19 UserMailbox {Amanda Hansen, Anna Bell, Anne Butler, Brenda Smith…}

It shows the number of all the different mailbox types you have and groups the names together.

Using the Sort option

Using the Sort option, you can sort the output by relating it to a specific property header. The values for the header will be sorted ascending by default. If you want to use descending sorting, you need to specify that.

  • Name
  • DisplayName
  • Alias
  • Office
  • ServerLegacyDN

In our example, we want to sort the output of the Get-Mailbox command by the property Alias.

See the PowerShell command syntax.

Get-Mailbox -ResultSize Unlimited | Sort Alias

Run the below PowerShell command example.

Get-Mailbox -ResultSize Unlimited | Sort Alias -Descending

The PowerShell output result.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
fd199cb4-2ebf-4171-96e2-… Susan.Brown EURPR02DG429-db133 99 GB (106,300,440,… fd199cb4-2ebf-4171-96e2-12fd75453e39
c32b2b27-d809-439a-a3e3-… Stephen.Hunter EURPR02DG597-db438 99 GB (106,300,440,… c32b2b27-d809-439a-a3e3-eb7a749eeb72
1e367b85-f0c0-4c9c-a16a-… Soren.Vest EURPR02DG387-db004 99 GB (106,300,440,… 1e367b85-f0c0-4c9c-a16a-22d132f1d8e6
e5c3a5e8-eeae-4829-94dc-… Ryan.Walker EURPR02DG514-db387 99 GB (106,300,440,… e5c3a5e8-eeae-4829-94dc-fb7228bcf8da
RoomTest8 RoomTest8 EURPR02DG611-db195 99 GB (106,300,440,… 274d72d7-cc30-4a64-bc33-c99ff96c3abf
85df102b-1330-4359-8e6b-… Rene.Gibs EURPR02DG489-db525 99 GB (106,300,440,… 85df102b-1330-4359-8e6b-240677b26454
Projector 8 Projector8 EURPR02DG512-db190 49.5 GB (53,150,220… 3c06bdad-3224-4b93-ac4e-fb7dcd23e0ce
Projector 21 Projector21 EURPR02DG597-db175 49.5 GB (53,150,220… 6f4d2832-2753-4433-aba9-11dd73c14e39
3bb176aa-d0ba-47f7-aecc-… Mary.James EURPR02DG233-db100 99 GB (106,300,440,… 3bb176aa-d0ba-47f7-aecc-f4837593006e
213a5a8b-0bcf-40cc-b114-… Laura.Terry EURPR02DG117-db074 99 GB (106,300,440,… 213a5a8b-0bcf-40cc-b114-edb1b2a423f4
12eefbb2-e5f4-4eec-bd18-… Ken.Walker EURPR02DG393-db032 99 GB (106,300,440,… 12eefbb2-e5f4-4eec-bd18-df7ca2f1ee6b
33a56fba-ed21-456d-90be-… Justin.Russel EURPR02DG387-db166 99 GB (106,300,440,… 33a56fba-ed21-456d-90be-ade268b9acc8

The PowerShell output is sorted by the Alias in descending order, meaning the last letters in the alphabet will come first in line.

:/>  Способы загрузки Windows 10-XP в безопасном режиме

Using the AutoSize option

The Autosize option is relevant when we choose to display information using Format-Table. When you use the ft option, the PowerShell output uses a predefined table row width.

The PowerShell console is not wide enough to display all the properties if you don’t open it in full screen. Because of the width limitation, PowerShell removes the other last default properties from the display, such as Database, ProhibitSendQuota, and ExternalDirectoryObjectId.

You can avoid this using the -Autosize parameter because PowerShell will customize the table row width to fit the values under the table headers.

Run the below PowerShell command example.

Get-Mailbox -ResultSize Unlimited | Format-Table -Autosize

See the PowerShell output result.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5 Amanda.Hansen EURPR02DG549-db028 99 GB (106,300,440,576 bytes) 41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5
82cd0d62-e974-4892-aca6-e0387abc62be Anna.Bell EURPR02DG037-db046 99 GB (106,300,440,576 bytes) 82cd0d62-e974-4892-aca6-e0387abc62be
5cae3874-442b-459c-8f33-3aee5b879275 Anne.Butler EURPR02DG275-db096 99 GB (106,300,440,576 bytes) 5cae3874-442b-459c-8f33-3aee5b879275
0f38d53f-cbe0-4844-86e9-1032a45ba31b Brenda.Smith EURPR02DG598-db076 99 GB (106,300,440,576 bytes) 0f38d53f-cbe0-4844-86e9-1032a45ba31b
411a8f10-0dfa-4034-a1e3-a8b6e4cad2f6 Brian.Mill EURPR02DG558-db051 99 GB (106,300,440,576 bytes) 411a8f10-0dfa-4034-a1e3-a8b6e4cad2f6
52a6c1c7-77d2-4109-99b9-a4076167b6e2 Carl.Hawk EURPR02DG234-db124 99 GB (106,300,440,576 bytes) 52a6c1c7-77d2-4109-99b9-a4076167b6e2
Catch All Catch.All EURPR02DG588-db346 49.5 GB (53,150,220,288 bytes) 182292ee-eaec-438b-bf14-f25dec9cf1cd
d5dc703a-45d0-4dc3-89ba-16f088925e41 Charles.Mitchel EURPR02DG517-db333 99 GB (106,300,440,576 bytes) d5dc703a-45d0-4dc3-89ba-16f088925e41
b602b148-2fcf-435a-9d34-ce72c3a8c748 Diana.Baker EURPR02DG060-db131 99 GB (106,300,440,576 bytes) b602b148-2fcf-435a-9d34-ce72c3a8c748
DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852} DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852} EURPR02DG219-db026 50 GB (53,687,091,200 bytes)

It shows the entire output result for all the properties of each mailbox.

Combination of display parameters

  • Sort
  • Format-Table
  • Group

PowerShell command syntax:

Get-Mailbox -ResultSize Unlimited | Sort RecipientTypeDetails | Format-Table Name, Alias -Group RecipientTypeDetails
  • First, it will get all the existing mailboxes in Exchange Online.
  • Then, it will Sort the mailboxes using the RecipientTypeDetails property.
  • We also use the Format-Table (ft) and only want to display the Alias and the Name properties.
  • Lastly, the option Group will display the information in sections according to the mailbox types.

See the PowerShell output result.

 RecipientTypeDetails: DiscoveryMailbox
Name Alias
---- -----
DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852} DiscoverySearchMailbox{D919BA05-46A6-415f-80AD-7E09334BB852} RecipientTypeDetails: EquipmentMailbox
Name Alias
---- -----
Projector 8 Projector8
Projector 21 Projector21 RecipientTypeDetails: RoomMailbox
Name Alias
---- -----
RoomTest8 RoomTest8 RecipientTypeDetails: SharedMailbox
Name Alias
---- -----
Catch All Catch.All
Info Box InfoBox RecipientTypeDetails: UserMailbox
Name Alias
---- -----
41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5 Amanda.Hansen
1e367b85-f0c0-4c9c-a16a-22d132f1d8e6 Soren.Vest
e5c3a5e8-eeae-4829-94dc-fb7228bcf8da Ryan.Walker
85df102b-1330-4359-8e6b-240677b26454 Rene.Gibs
3bb176aa-d0ba-47f7-aecc-f4837593006e Mary.James
213a5a8b-0bcf-40cc-b114-edb1b2a423f4 Laura.Terry
12eefbb2-e5f4-4eec-bd18-df7ca2f1ee6b Ken.Walker
2ab57f6a-6824-40a3-8fb0-d4357e8b91b1 John.Doe2
c32b2b27-d809-439a-a3e3-eb7a749eeb72 Stephen.Hunter
29a12fd8-bbd2-440f-b457-8e304200a85d Frank.Olsen
b602b148-2fcf-435a-9d34-ce72c3a8c748 Diana.Baker
d5dc703a-45d0-4dc3-89ba-16f088925e41 Charles.Mitchel
52a6c1c7-77d2-4109-99b9-a4076167b6e2 Carl.Hawk
411a8f10-0dfa-4034-a1e3-a8b6e4cad2f6 Brian.Mill
0f38d53f-cbe0-4844-86e9-1032a45ba31b Brenda.Smith
5cae3874-442b-459c-8f33-3aee5b879275 Anne.Butler
82cd0d62-e974-4892-aca6-e0387abc62be Anna.Bell
33a56fba-ed21-456d-90be-ade268b9acc8 Justin.Russel
fd199cb4-2ebf-4171-96e2-12fd75453e39 Susan.Brown

Get all mailboxes in Out-Gridview

We will get all the Exchange Online mailboxes and send the output to an interactive table (Out-GridView).

Run the below PowerShell command.

Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, Alias, Identity, RecipientTypeDetails | Out-GridView -Title "All Mailboxes"

The Out-GridView appears with a detailed list of mailboxes where you can filter and search the results.

Управление почтовым ящиком пользователя с помощью power shell

Get-EXOMailbox PowerShell cmdlet

You can use the Get-EXOMailbox cmdlet to retrieve results faster than the Get-Mailbox cmdlet. However, it doesn’t work in Exchange Server on-premises and it only works in Exchange Online.

Note: We recommend using the Get-EXOMailbox cmdlet for better performance and reliability.

All module versions contain nine exclusive Get-EXO* cmdlets for Exchange Online PowerShell optimized for speed in bulk data retrieval.

See the below list with the improved Exchange Online PowerShell cmdlets that are available only in the module.

EXO module cmdletOlder related cmdlet
Get-EXOMailboxGet-Mailbox
Get-EXORecipientGet-Recipient
Get-EXOCasMailboxGet-CASMailbox
Get-EXOMailboxPermissionGet-MailboxPermission
Get-EXORecipientPermissionGet-RecipientPermission
Get-EXOMailboxStatisticsGet-MailboxStatistics
Get-EXOMailboxFolderStatisticsGet-MailboxFolderStatistics
Get-EXOMailboxFolderPermissionGet-MailboxFolderPermission
Get-EXOMobileDeviceStatisticsGet-MobileDeviceStatistics

We will use the Get-Mailbox cmdlet to view mailbox object information. When you use the Get-Mailbox cmdlet to display information about mailboxes, the information will be displayed in a table format.

Run the most basic PowerShell cmdlet.

Get-Mailbox

The PowerShell output is based on a predefined output format with a header for each property.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
41377e9c-dc47-46c0-b4a5-… Amanda.Hansen EURPR02DG549-db028 99 GB (106,300,440,… 41377e9c-dc47-46c0-b4a5-1d5bbdcb5cc5
82cd0d62-e974-4892-aca6-… Anna.Bell EURPR02DG037-db046 99 GB (106,300,440,… 82cd0d62-e974-4892-aca6-e0387abc62be
5cae3874-442b-459c-8f33-… Anne.Butler EURPR02DG275-db096 99 GB (106,300,440,… 5cae3874-442b-459c-8f33-3aee5b879275
0f38d53f-cbe0-4844-86e9-… Brenda.Smith EURPR02DG598-db076 99 GB (106,300,440,… 0f38d53f-cbe0-4844-86e9-1032a45ba31b
411a8f10-0dfa-4034-a1e3-… Brian.Mill EURPR02DG558-db051 99 GB (106,300,440,… 411a8f10-0dfa-4034-a1e3-a8b6e4cad2f6
52a6c1c7-77d2-4109-99b9-… Carl.Hawk EURPR02DG234-db124 99 GB (106,300,440,… 52a6c1c7-77d2-4109-99b9-a4076167b6e2
Catch All Catch.All EURPR02DG588-db346 49.5 GB (53,150,220… 182292ee-eaec-438b-bf14-f25dec9cf1cd
d5dc703a-45d0-4dc3-89ba-… Charles.Mitchel EURPR02DG517-db333 99 GB (106,300,440,… d5dc703a-45d0-4dc3-89ba-16f088925e41
b602b148-2fcf-435a-9d34-… Diana.Baker EURPR02DG060-db131 99 GB (106,300,440,… b602b148-2fcf-435a-9d34-ce72c3a8c748

It shows the Name, Alias, Database, Mailbox size quota, and Object ID for each mailbox.

Get all existing mailboxes information

When you use the Get-Mailbox cmdlet without specifying anything, it will not show all the existing mailboxes in your organization. If you have many mailboxes, you must add the -ResultSize parameter with the value Unlimited.

Get a list of all the existing mailboxes with the below PowerShell command.

Get-Mailbox -ResultSize Unlimited

The PowerShell output displays a complete list of all the existing mailboxes in Exchange Online.

Count total mailboxes

Count the number of Exchange Online mailboxes.

(Get-Mailbox -ResultSize Unlimited).Count

The PowerShell output shows the number of mailboxes.

Get single mailbox information

To get information about a specific mailbox, you must provide the -Identity parameter.

You can use one of the below values that identify the mailbox:

  • Name
  • Alias
  • Distinguished name (DN)
  • Canonical DN
  • Domain
  • Email address
  • GUID
  • LegacyExchangeDN
  • SamAccountName
  • User ID or user principal name (UPN)

Use the PowerShell command syntax.

Get-Mailbox -Identity "identity"

Run the PowerShell command example.

Get-Mailbox "Brenda.Smith@m365info.com"

The PowerShell output result is displayed in a table format with a predefined header for each object property.

Name Alias Database ProhibitSendQuota ExternalDirectoryObjectId
---- ----- -------- ----------------- -------------------------
0f38d53f-cbe0-4844-86e9-… Brenda.Smith EURPR02DG598-db076 99 GB (106,300,440,… 0f38d53f-cbe0-4844-86e9-1032a45ba31b

It shows the Name, Alias, Database, Mailbox size quota, and Object ID for a single mailbox.

Get disabled mailboxes

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.AccountDisabled -eq $true } | Format-Table Alias, UserPrincipalName, AccountDisabled

Get inactive mailboxes

Get-Mailbox -InactiveMailboxOnly -ResultSize Unlimited | Format-Table DisplayName, PrimarySMTPAddress, WhenSoftDeleted

Get mailbox archive status

Get all mailboxes with an active archive mailbox.

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ArchiveStatus -eq 'Active' } | Format-Table UserPrincipalName, RecipientTypeDetails, ArchiveStatus

Get all mailboxes with an inactive archive mailbox.

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ArchiveStatus -ne 'Active' } | Format-Table UserPrincipalName, RecipientTypeDetails, ArchiveStatus

Get mailbox last logon time

Get all mailboxes with their last logon time.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object { $_.LastLogonTime } | Format-Table DisplayName, LastLogonTime
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object { $_.LastLogonTime –le ((Get-Date).AddMonths(-2)) } | Format-Table DisplayName, LastLogonTime

Get mailbox created date and time

Get all mailboxes with their created date and time

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.WhenCreated } | Format-Table UserPrincipalName, WhenCreated

Get all mailboxes that were created within the last 2 years from the current date.

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.WhenCreated –ge ((Get-Date).AddYears(-2)) } | Format-Table UserPrincipalName, WhenCreated

Get hidden mailboxes from Global Address List (GAL)

Get all mailboxes that are hidden from the Global Address List (GAL).

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.HiddenFromAddressListsEnabled -eq $true } | Format-Table UserPrincipalName, HiddenFromAddressListsEnabled

Get mailboxes with forwarding rules

Get all mailboxes that have forwarding addresses configured to internal or external recipients.

Get-Mailbox -ResultSize Unlimited | Where-Object { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingSmtpAddress -ne $null) } | Format-Table UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward

Get soft-deleted mailboxes

Get all mailboxes that are soft-deleted.

Get-Mailbox -ResultSize Unlimited -SoftDeletedMailbox | Format-Table Name, Alias, IsSoftDeletedByRemove, IsInactiveMailbox

Get mailboxes time zone and language

Get all mailboxes with their time zone and language.

Get-Mailbox -ResultSize Unlimited | Get-MailboxRegionalConfiguration | Format-Table Identity, Language, DateFormat, TimeFormat, TimeZone

How to Add Mailbox permissions using PowerShell?

Automating mailbox permission management using PowerShell scripts can save you time and reduce the risk of errors. Here are some examples of PowerShell scripts that you can use to automate mailbox permission management:

  1. Connect to Office 365 using the following command: Connect-ExchangeOnline -UserPrincipalName <UPN>.
  2. Run the following command to grant Full Access permission to a mailbox: Add-MailboxPermission -Identity <Mailbox> -User <User> -AccessRights FullAccess.
  3. Run the following command to grant Send As permission to a mailbox: Add-RecipientPermission -Identity <Mailbox> -Trustee <User> -AccessRights SendAs
  4. Run the following command to grant Send on Behalf permission to a mailbox: Set-Mailbox -Identity <Mailbox> -GrantSendOnBehalfTo <User>.

Connect to Exchange Online from PowerShell

To add mailbox permissions in Office 365 PowerShell, we must first establish a connection to Exchange Online PowerShell. Here’s how we do it:

Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com

Granting Full access to a mailbox in Office 365 PowerShell

The most common permission to grant is full mailbox access. This allows the recipient to log into the mailbox and fully manage it – reading, sending, and deleting emails as if they are the owner. Here is how to grant full access to a mailbox:

  1. Open PowerShell on your computer and run it as an administrator.
  2. Connect to Exchange Online PowerShell using the steps outlined above.
  3. To add full mailbox permission, Use the Add-MailboxPermission cmdlet. Here is an example:
Add-MailboxPermission -Identity <Mailbox-Identity> -User <User-ID> -AccessRights FullAccess -InheritanceType All

You can change the Ownership of a Mailbox using:

Add-MailboxPermission -Identity <Mailbox-Identity> -Owner <User-ID>
Add-MailboxPermission -Identity <MailboxIdentity> -User <User> -AccessRights ReadPermission,ChangePermission

Grant “Send on Behalf” permission using PowerShell

Set-Mailbox -Identity <Mailbox-Identity> -GrantSendOnBehalfTo <User-ID>

PowerShell to set “Send as” permission in Exchange Online

Similarly, To grant “Send as” permissions, use the Add-RecipientPermission cmdlet:

Add-RecipientPermission -Identity <Mailbox-Identity> -Trustee <User-ID> -AccessRights SendAs -Confirm:$false

Verify Mailbox Permissions using PowerShell

Get-MailboxPermission -Identity <Mailbox-Identity> -User <User-ID>
Get-MailboxPermission -Identity user@domain.com

Delete user mailbox

Soft delete user mailbox

PowerShell command syntax:

Remove-Mailbox -Identity "<User Identity>" -Confirm:$False

PowerShell command example:

Remove-Mailbox -Identity "KellyTest" -Confirm:$False

Bulk soft delete user mailbox

Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailBox")' -ResultSize Unlimited | Remove-Mailbox -Confirm:$False

Hard delete user mailbox

Inactive Mailboxes Report

This screenshot shows how you can generate the inactive mailboxes report using the get-mailbox cmdlet.
Figure 4: Looking for inactive mailboxes using LastLogonTime and LastUserActionTime. | Used with permission from Microsoft. View Full Size

How Does the Script Work?

Let’s break down the script:

  1. To get information about all your Microsoft 365 mailboxes, use the Get-Mailbox -ResultSize Unlimited command.
  2. Run a foreach loop over the fetched mailboxes. Pull out the individual mailbox statistics by using the Get-MailboxStatistics cmdlet and $_.UserPrincipalName from each of them and passing this to the -Identity parameter to fetch the individual mailbox statistics.
  3. Display only the DisplayName, LastLogonTime, and LastUserActionTime properties of the fetched mailboxes.
:/>  Как отключить Интернет на компьютере на время

How to Use Enable-RemoteMailbox in PowerShell

Now that you know what the Enable-RemoteMailbox command is for and its meaning, it’s time to learn how to use it.

Step 1: Connect to Exchange Online PowerShell

Step 2: Identify the User and Mailbox Parameters

Having this information in advance ensures a seamless and accurate execution of the Enable-RemoteMailbox command in PowerShell, preventing potential execution issues.

If you want to retrieve mail-related attributes, you can do so by running the Get-RemoteMailbox cmdlet before running Enable-RemoteMailbox on PowerShell.

Step 3: Run the Enable-RemoteMailbox Command in PowerShell

The command can be modified further to match your needs, for example:

Bulk export all mailboxes to CSV file

We will bulk export all the Exchange Online mailboxes to a CSV file. After that, we can open it with Microsoft Excel.

Run the below PowerShell command.

Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, Alias, Identity, RecipientTypeDetails | Export-Csv "C:\temp\AllMailboxes.csv" -Encoding UTF8 -NoTypeInformation

PowerShell to Add Mailbox Permissions in Office 365

Prerequisites

  • Exchange Administrator or Global Administrator Access in Microsoft 365 environment
  • Exchange Online PowerShell module installed – You can install the Exchange Online PowerShell module with my other post: How to Install the Exchange Online PowerShell module?

Different Types of Mailbox Permissions

Mailbox permissions allow granular access to mailboxes by specifying permission levels. Some common examples include:

  • Full Access: This permission allows one user to log in and access another user’s mailbox, essentially having the same rights as the mailbox owner.
  • Send As: Enables a user to send emails from another user’s mailbox, appearing to come directly from the mailbox owner.
  • Send on Behalf: Allows a user to send an email on behalf of the mailbox owner, which displays as “User1 on behalf of User2”.

Understanding the Add-MailboxPermission cmdlet

Add-MailboxPermission
-Identity <MailboxIdentity>
-User <User>
-AccessRights <AccessRights>
[-InheritanceType <InheritanceType>]
[-Automapping <$true | $false>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
  • Identity: The mailbox identity that you want to add permissions to.
  • User: The user or group that you want to grant permissions to.
  • AccessRights: The level of access that you want to grant. This can be full access, send-as, or send-on-behalf.
  • InheritanceType (optional): The type of inheritance that you want to apply to the permissions.
  • Automapping (optional): Specifies whether the mailbox is automatically mapped to the user’s Outlook profile. By default, its false.

Microsoft 365 mailbox types

There are four different mailbox types in Microsoft 365:

  1. User mailbox
  2. Shared mailbox
  3. Room mailbox
  4. Equipment mailbox

Create new user mailbox

  • Alias
  • Name
  • FirstName
  • LastName
  • DisplayName
  • MicrosoftOnlineServicesID (User email address)
New-Mailbox -Alias "Kelly1" -Name "KellyTest" -FirstName "Kelly" -LastName "Test" -DisplayName "Kelly Test" -MicrosoftOnlineServicesID "KellyTest@m365info.com" -Password (ConvertTo-SecureString -String 'P@s$w0rd' -AsPlainText -Force) -ResetPasswordOnNextLogon $true
PS C:\> New-Mailbox -Alias "Kelly1" -Name "KellyTest" -FirstName "Kelly" -LastName "Test" -DisplayName "Kelly Test" -MicrosoftOnlineServicesID "KellyTest@m365info.com" -Password (ConvertTo-SecureString -String 'P@s$w0rd' -AsPlainText -Force) -ResetPasswordOnNextLogon $true
Name Alias Database ProhibitSendQuota
---- ----- -------- -----------------
KellyTest Kelly1 EURPR02DG514-db460 99 GB (106,300,44...
WARNING: After you create a new mailbox, you must go to the Office 365 Admin Center and assign
the mailbox a license, or it will be disabled after the grace period.

Possible Errors You Might Face

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

  • Typos in your PowerShell script: You might have typos even while copying/pasting scripts. Save your scripts in separate .ps1 files, and then run them. This not only saves time but also prevents your script from running into unnecessary errors.
  • Providing incorrect login credentials: Ensure that you get your credentials right to prevent yourself from running into this embarrassing error.

How to Use the Enable-RemoteMailbox Cmdlet in PowerShell

  • The Enable-RemoteMailbox cmdlet serves as a powerful tool for centralizing mailbox management, facilitating cloud migrations, and enhancing overall control in Exchange environments, making it an invaluable asset for organizations leveraging PowerShell for email infrastructure;
  • Before running this command, it’s important to have all the mailbox and user attributes for the command to work smoothly. If you don’t know this information, you can retrieve it by using Get-RemoteMailbox;
  • In case the command is not working as expected, check if you have sufficient admin permission and make sure you are using the correct user and mailbox parameters. If you need further assistance, don’t hesitate to contact your organization’s administration.

Mailbox Storage Report

This generates storage reports about individual Microsoft 365 mailboxes (and identifies mailboxes that are running out of storage space), as shown in Figure 5.

This screenshot shows how you can generate the mailbox storage report using the get-mailbox cmdlet.
Figure 5: Using the Get-Mailbox cmdlet to fetch the mailbox storage statistics. | Used with permission from Microsoft. View Full Size

Connect to Exchange Online

Before you start, you need to Install Exchange Online PowerShell module.

Connect-ExchangeOnline

For Those Who Like to Watch and Learn

Prerequisites to Run the Enable-RemoteMailbox Script

Before running PowerShell commands, ensure compliance with the required permissions and prerequisites.

  1. Connect to Exchange Online: Log in with admin credentials using a valid Microsoft Account to connect to Exchange Online PowerShell;
  2. Run Get-ManagementRole Command: Once logged in, execute the command: Get-ManagementRole -Cmdlet. Replace the -cmdlet part with “Enable-RemoteMailbox,” so it will look like this: Get-ManagementRole Enable-RemoteMailbox;
  3. Check Required Permissions: After running the command, review the list of roles needed for Get-MessageTrace. For additional roles or permissions, contact your organization administrator for assistance.

Prerequisite

Note: You can get all the commands available within the ExchangeOnlineMangement PowerShell module by running the Get-Command -Module ExchangeOnlineManagement command. This article only serves as a quick-start guide for Get-family cmdlets of the ExchangeOnlineManagement PowerShell module that help you retrieve crucial Microsoft 365 mailbox information. For details about the commands that are listed, see this ExchangePowerShell documentation from Microsoft. Or search for Microsoft’s online help right from the PowerShell console by running the Help <command name> command.