Check Exchange Online for Newly Created Mailboxes Using PowerShell

Checking your Exchange Online for newly created mailboxes is a good practice and can help achieve two objectives, keep an eye on growth and security.

By default, when Exchange Online creates a mailbox, an attribute called WhenMailboxCreated is populated with the creation date, which we can retrieve with the Exchange Online PowerShell module.

Script

The following PowerShell script will display a list of the mailboxes created in the last 30 days. To go back more than 30 days, simply change the value -30 to the number of days you would like to go back.

To run the script, make sure you install the Exchange Online V2 PowerShell module using the following cmdlet.

Install-Module -Name ExchangeOnlineManagement

Save the code below or run each line.

$setdate = (Get-Date).AddDays(-30)
$result = (Get-ExoMailbox -ResultSize Unlimited -Filter "WhenMailboxCreated -gt '$setdate'" -Properties WhenMailboxCreated | Select-object WhenMailboxCreated, UserPrincipalName, DisplayName)
if($result -eq $null)
 {
  "No new mailboxes"
 }
else
 {
$result
 }


by