Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitWhen managing a growing Microsoft 365 environment, it's essential to track newly provisioned mailboxes—especially to ensure onboarding consistency, license assignments, and security baselines. This Graph PowerShell script helps you list recently created mailboxes for your tenant.
# Connect to Microsoft Graph with necessary permissions
Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All"
# Set the threshold for 'recently created' (last 30 days)
$startDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ssZ")
# Step 1: Fetch recently created tenant users (UserType = Member)
$recentUsers = Get-MgUser -All `
-Filter "UserType eq 'Member' and createdDateTime ge $startDate" `
-Property DisplayName, UserPrincipalName, Mail, CreatedDateTime
# Step 2: Filter locally to keep only mail-enabled users
$recentMailboxes = $recentUsers | Where-Object { $_.Mail -ne $null -and $_.Mail -ne "" } |
Select-Object DisplayName, UserPrincipalName,
@{Name = "Email"; Expression = { $_.Mail }},
@{Name = "Created On"; Expression = { $_.CreatedDateTime }}
# Step 3: Display the results
$recentMailboxes | Format-Table -AutoSize
Let's break it down step-by-step:
Establishes a secure session with Microsoft Graph. You'll need delegated permissions like:
đź’ˇ Tip: Run Disconnect-MgGraph before reconnecting if you're switching accounts.
$startDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ssZ")
This defines the window (last 30 days) for evaluating newly created users.
-Filter "UserType eq 'Member' and createdDateTime ge $startDate"
This excludes all Guest users (UserType eq 'Guest'), such as external collaborators using Gmail, Yahoo, etc.
Where-Object { $_.Mail -ne $null -and $_.Mail -ne "" }
Since Graph API doesn’t support filtering on mail ne null directly, this step is handled in PowerShell after fetching the results.
Select-Object DisplayName, UserPrincipalName, Email, Created On
Neatly organizes the results in a readable table format.
You can build on this script in several ways:
$recentMailboxes | Export-Csv -Path "RecentMailboxes.csv" -NoTypeInformation -Encoding UTF8
Error | Cause | Solution |
Filter operator 'NotEqualsMatch' is not supported | You tried to use mail ne null in the -Filter | Graph API doesn’t support this. Do the null-check in PowerShell instead. |
Insufficient privileges to complete the operation | Missing Graph permissions | Ensure you have delegated User.Read.All and Directory.Read.All. |
Connect-MgGraph not recognized | Microsoft Graph module not installed | Run Install-Module Microsoft.Graph -Scope CurrentUser |
This Graph PowerShell script gives you a clean and efficient way to track recently created tenant mailboxes, excluding external/guest users. It’s ideal for monitoring provisioning processes, validating licensing, or auditing new account creation trends in your Microsoft 365 tenant.
© m365corner.com. All Rights Reserved. Design by HTML Codex