Microsoft 365 administrators often need to track recently created user accounts for security audits, compliance checks, and IT reporting. By using Microsoft Graph PowerShell, we can efficiently retrieve all users created within the last 90 days and display relevant details such as UserPrincipalName (UPN), Email Address, and Display Name.
This article provides a PowerShell script to fetch and display these users in the console.
# Connect to Microsoft Graph (Ensure you have necessary permissions)
Connect-MgGraph -Scopes "User.Read.All"
# Get the date 90 days ago from today
$startDate = (Get-Date).AddDays(-90).ToString("yyyy-MM-ddTHH:mm:ssZ")
# Fetch users created in the last 90 days
$recentUsers = Get-MgUser -All -Filter "createdDateTime ge $startDate" -Property UserPrincipalName, DisplayName, Mail, createdDateTime
# Display results in console
$recentUsers | Select-Object UserPrincipalName, Mail, DisplayName, createdDateTime | Format-Table -AutoSize
$recentUsers | Select-Object UserPrincipalName, Mail, DisplayName, createdDateTime | Export-Csv -Path "C:\Users\RecentUsers.csv" -NoTypeInformation -Encoding UTF8
$recentUsers = Get-MgUser -All -Filter "createdDateTime ge $startDate and department eq 'IT'" -Property UserPrincipalName, DisplayName, Mail, createdDateTime
Error | Cause | Solution |
Invalid filter clause | Incorrect OData syntax in the -Filter parameter | Ensure that createdDateTime is formatted correctly (ISO 8601) |
Access Denied | Insufficient permissions | Assign User.Read.All permissions to the connected account |
No users returned | No users created in the last 90 days | Adjust the date range to fetch data for a longer period |
This Graph PowerShell script allows Microsoft 365 administrators to efficiently fetch and track newly created users within a specific timeframe. Whether for security audits, HR onboarding, or compliance tracking, this script provides a quick way to retrieve essential user information. By extending it with CSV exports, email notifications, and automation, IT teams can streamline user management processes.
© m365corner.com. All Rights Reserved. Design by HTML Codex