In the current article, we will review how to use the PowerShell commands for managing…
Exchange Online – Display and Export information using PowerShell | Office 365
In the current article, we review the how to use the PowerShell command Get-Mailbox for – display and export information about Exchange Online mailboxes.
One of the most basic needs for Exchange Online administrator is – the ability to create reports that include information about the Exchange Online resources such as Mailbox’s, Distribution Groups, etc.
This is Where PowerShell “Shine”!
The GUI Interface (WEB Interface) includes limited ability to display information and have no option to export data or to create “wide area” searches for a particular object or, object with a specific parameter (property). When using the PowerShell, the options are unlimited.
This article includes a mixture of PowerShell commands for displaying and exporting information from the Exchange Online environment.
1. Display information by Mailbox Type
1.1 – Display List of all Mailbox’s type
PowerShell command syntax:
Get-Mailbox
Adjustments & Customizations
Filter the display output details
PowerShell command syntax:
Get-Mailbox -ResultSize Unlimited | Where {$_.name -notlike '*DiscoverySearchMailbox*'}
1.2 -Display List of all Mailbox’s Summary
PowerShell command syntax:
Get-User | Group RecipientTypeDetails
1.3 -Display List of office 365 Users Mailbox’s
PowerShell command syntax:
Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name,Alias
1.4 – Display List of Room Mailbox’s
PowerShell command syntax:
Get-MailBox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select Name,Alias
1.5 – Display List of Equipment Mailbox’s
PowerShell command syntax:
Get-MailBox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select Name,Alias
1.6 – Display List of Shared Mailbox’s
PowerShell command syntax:
Get-MailBox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select RecipientTypeDetails,Name,Alias
1.7 – Count the Mailbox’s number
PowerShell command syntax:
(Get-Mailbox -ResultSize Unlimited).Count
2. Find and Display information about Email Address
2.1 – Display ALL recipients Primary + Alias Email Address + SIP Address
PowerShell command syntax:
Get-Mailbox -ResultSize Unlimited |FL EmailAddresses
Adjustments & Customizations
Filter the display output details
PowerShell command syntax:
Get-Mailbox -ResultSize Unlimited | Where {$_.name -Notlike '*DiscoverySearchMailbox*'} |FL EmailAddresses
2.2 -Display every Alias for each recipients + count Alias
PowerShell command syntax:
Get-Mailbox | FL name, @{name="count";expression={[array]($_.EmailAddresses).Count}},EmailAddresses
2.3 -Display Primary + Alias Email Address + SIP Address for specific Mailbox
PowerShell command syntax:
Get-Mailbox <Identity>| Select -Expand EmailAddresses Alias
PowerShell command example:
Get-Mailbox John | Select -Expand EmailAddresses Alias
2.4 -Display Office 365 users UPN names
PowerShell command syntax:
Get-MsolUser | Select DisplayName,UserPrincipalName
3. Find Mail Recipients with specific Domain name suffix
3.1 – Find Office 365 users that have UPN With specific Domain name suffix
PowerShell command syntax:
Get-MsolUser –DomainName <Domain Suffix>| FL UserPrincipalName
PowerShell command example:
Get-MsolUser -DomainName o365info.com | FL UserPrincipalName
3.2 – Find Mailbox’s Email Addresses that have specific Domain name suffix
PowerShell command syntax:
Get-Mailbox | Where {$_.emailaddresses -like "*<Domain Suffix>*"} | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-Mailbox | Where {$_.emailaddresses -like "*o365info.com*"} | FL Name,Alias,EmailAddresses
3.3 – Find Distribution Groups Email Addresses that have specific Domain name suffix
PowerShell command syntax:
Get-DistributionGroup | Where {$_.emailaddresses -like "*<Domain Suffix>*"} | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-DistributionGroup | Where {$_.emailaddresses -like "*o365info.com*"} | FL Name,Alias,EmailAddresses
3.4 – Find Contacts Email Addresses that have specific Domain name suffix
PowerShell command syntax:
Get-Mailcontact | Where {$_.emailaddresses -like "*<Domain Suffix>*"} | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-Mailcontact | Where {$_.emailaddresses -like "*o365info.com*"} | FL Name,Alias,EmailAddresses
4. Find Mail Recipients with specific Attribute
4.1 – Find Mailbox’s Email Addresses that have specific Alias
PowerShell command syntax:
Get-Mailbox | Where {$_.EmailAddresses -like "*<Alias>*"} | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-Mailbox | Where {$_.EmailAddresses -like "*John*"} | FL Name,Alias,EmailAddresses
4.2 – Find Distribution Groups Email Addresses that have specific Alias
PowerShell command syntax:
Get-DistributionGroup | Where {$_.EmailAddresses -like "*<Alias>*"} | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-DistributionGroup | Where {$_.EmailAddresses -like "*John*"} | FL Name,Alias,EmailAddresses
4.3 – Find Contacts Email Addresses that have specific Alias
PowerShell command syntax:
Get-Mailcontact | Where {$_.EmailAddresses -like "*<Alias>*"} | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-Mailcontact| Where {$_.EmailAddresses -like "*John*"} | FL Name,Alias,EmailAddresses
4.4 – Find Email Addresses that have specific Alias + specific Domain name suffix
PowerShell command syntax:
Get-Mailbox | Where { $_.Name -like "*<Alias>*" -and $_.EmailAddresses -like "*<Domain Suffix>*" } | FL Name,Alias,EmailAddresses
PowerShell command example:
Get-Mailbox | Where { $_.Name -like "*John*" -and $_.EmailAddresses -like "*o365info.com*" } | FL Name,Alias,EmailAddresses
4.5 – Find Email Addresses that have specific Alias + specific Domain name suffix
PowerShell command syntax:
Get-Mailbox | Where { $_.UsageLocation -like "**" } |FL Name,Alias,EmailAddres,UsageLocation
PowerShell command example:
Get-Mailbox | Where { $_.UsageLocation -like "*US*" } |FL Name,Alias,EmailAddres,UsageLocation
5. View Mailbox Statistics
information about mailbox and folder size
5.1 – Display information about mailbox size (Mailbox Statistics)
PowerShell command syntax:
Get-MailboxStatistics <Identity> | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount
PowerShell command example:
Get-MailboxStatistics John | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount
5.2 – Display information about ALL of existing mailbox size
PowerShell command syntax:
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount
PowerShell command example:
Get-MailboxStatistics John | FL DisplayName,StorageLimitStatus,TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount
5.3 – Display information about specific folder size
PowerShell command syntax:
Get-MailboxStatistics <Identity> -FolderScope <folder> | Select Name,FolderSize,ItemsinFolder
PowerShell command example:
Get-MailboxStatistics John -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder
information about mailbox Quotas size
5.4 – View all Quotas assigned to a single Mailbox
PowerShell command syntax:
Get-Mailbox <Identity>| Fl *Quota
PowerShell command example:
Get-Mailbox John | FL *Quota
5.5 – View all Quotas assigned to ALL Mailbox’s
PowerShell command syntax:
Get-Mailbox -ResultSize Unlimited | FL DisplayName,Alias,*Quota
5.6 – View all Quotas assigned to a single Archive Mailbox
PowerShell command syntax:
Get-MailboxStatistics <Identity> -Archive | FL DisplayName,Alias,*Quota
PowerShell command example:
Get-MailboxStatistics John -Archive | FL DisplayName,Alias,*Quota
5.7 – View Statistic of all Archive Mailboxes
PowerShell command syntax:
Get-Mailbox -Archive -ResultSize Unlimited | Get-MailboxStatistics -Archive | Select DisplayName,StorageLimitStatus,@{name="TotalItemSize (MB)";expression={[math]::Round(($_.TotalItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},@{name="TotalDeletedItemSize (MB)";expression={[math]::Round(($_.TotalDeletedItemSize.Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}},ItemCount,DeletedItemCount | Sort "TotalItemSize (MB)" -Descending
5.8 – Display list of Active mailboxes and users
PowerShell command syntax:
Get-Mailbox -Resultsize unlimited| Get-MailboxStatistics | Where {$_.lastlogontime -ne $Null} | Select Displayname
5.9 – Display list inactive Mailbox accounts in Office 365
PowerShell command syntax:
Get-mailbox -Resultsize unlimited| Get-MailboxStatistics | Select Displayname,Lastlogontime | Sort-Object LastLogonTime
6. Display Mail recipients
6.1 – Display list of Distribution Groups
PowerShell command syntax:
Get-DistributionGroup | FL Name,DisplayName,GroupType,PrimarySmtpAddress
6.2 – Display list of Mail contacts
PowerShell command syntax:
Get-MailContact
7. Export information about Mailbox’s to file (CSV Format)
7.1 – Export User Mailbox’s information
PowerShell command syntax:
Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV <Path>
PowerShell command example:
Get-Mailbox -Filter '(RecipientTypeDetails -eq "UserMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV C:\Info\o365-User-Mailbox.csv
7.2 – Export Room Mailbox’s information
PowerShell command syntax:
Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV <Path>
Export Equipment Mailbox’s information
PowerShell command syntax:
Get-Mailbox -Filter '(RecipientTypeDetails -eq "EquipmentMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV <Path>
7.3 – Export Shared Mailbox’s information
PowerShell command syntax:
Get-Mailbox -Filter '(RecipientTypeDetails -eq "SharedMailbox")' | Select RecipientTypeDetails,Name,Alias | Export-CSV <Path> -NoTypeInformation
7.4 – Export information about mailboxes content (folders, items in folder etc.)
PowerShell command syntax:
Get-Mailbox | Select-Object alias | ForEach-Object {Get-MailboxFolderStatistics -Identity $_.alias | Select Identity,ItemsInFolder,FolderSize} | Export-CSV <Path> -NoTypeInformation
7.5 – Export information about mailboxes LastLogonTime + LastLogoffTime
PowerShell command syntax:
Get-Mailbox -ResultSize unlimited | Get-MailboxStatistics | Select DisplayName,lastlogontime,lastlogofftime | Sort-Object DisplayName -descending | Export-CSV <Path> -NoTypeInformation
If I want to manage holds on SharePoint list items in SharePoint online.. which api to use.
if anyone have any sample code please suggest..
How to delete Bulk users through power shell????
Thanks TC, we work with Exchange Online and that worked well.CheersK
@Anonymous:
I have mailboxes in Exchange Online also. I just used the “totalitemsize” and “totaldeleteditemsize” as values and removed all of the calculations. The results for those columns include a GB/MB/KB value with a bytes value in parentheses. I then converted the .csv to .xlsx and used find and replace to remove the bytes values from those columns. You can use (* bytes) in the “find” field and leave the “replace” field blank. For reference, here’s the cmdlet I used:
get-mailbox -resultsize unlimited | get-mailboxstatistics | select-object displayname,lastlogontime,lastlogofftime,storagelimitstatus,totalitemsize,totaldeleteditemsize,itemcount,deleteditemcount | sort-object displayname -ascending | export-csv c:filesmbxinfo.csv
Hope that helps,
TC
Generally I like this article a lot! but…We use ExchangeOnline Office 365 and the mailbox statistics scripts don’t populate the TotalItemSize and TotalDeletedItemSize attributes. I know this is related to the serialisation of data sent back to powershell. That’s why the script uses clumsy string manipulation techniques to solve the problem but it still doesn’t work for us. Any ideas for troubleshooting please?