Get mailbox folder statistics from Exchange Online / Office 365
This short and simple example shows how to connect to Exchange Online services to get mailbox folder statistics from Exchange Online / Office 365 via PowerShell.
Hope it helps.
# Sample PS to connect Exchange Online and to get mailbox and inbox folder item count.
# Osman Shener
# Get Credentials for Office 365
$Creds = Get-Credential
# Connect to Office 365 services
Connect-MsolService –Credential $Creds
# Create session to Exchange Online
$EOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection
Import-PSSession $EOSession -DisableNameChecking
# The mailbox owner
$TheUser = "Osman Shener"
# Get total item count in the mailbox (all items)
$TotalItemsCount = Get-MailboxStatistics -Identity $TheUser
# Get total item count in the Inbox folder
$InboxItemsCount = Get-MailboxFolderStatistics -Identity $TheUser -FolderScope Inbox
# Print the results
$TheUser + " has " + $TotalItemsCount.ItemCount + " items in the mailbox, " + $InboxItemsCount.ItemsInFolder + " of them are in the Inbox folder."
- For Office 365 operated by 21Vianet, use the ConnectionUri value:
- For Office 365 Germany, use the ConnectionUri value:
Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Windows PowerShell window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you’ll need to wait for the sessions to expire. To disconnect the remote PowerShell session, run the following command.