Inactive user accounts can pose security risks and consume unnecessary Microsoft 365 licenses. Identifying these accounts helps administrators optimize resource usage and enforce security policies. In this guide, we’ll explore what defines an inactive user, how long a user account should be inactive before being flagged, and how to fetch inactive user accounts using Microsoft Graph PowerShell.
An inactive user is an account that has not signed into Microsoft 365 services for a defined period. These accounts may belong to employees who have left the organization, temporary users, or accounts that were created but never used.
Inactive accounts can:
Organizations define inactivity based on their policies, but common benchmarks include:
In this guide, we will fetch users who have been inactive for 90 days, but this value can be adjusted as per your organization’s needs.
You can use the following Graph PowerShell script to identify inactive users in your Microsoft 365 tenant.
Ensure you have installed the Microsoft Graph PowerShell module and are signed in with the necessary permissions.
Connect-MgGraph -Scopes "User.Read.All"
# Define the inactivity period (e.g., users inactive for the past 90 days)
$daysInactive = 90
$inactiveSince = (Get-Date).AddDays(-$daysInactive).ToString("yyyy-MM-ddTHH:mm:ssZ")
# Get all users with sign-in activity data
$inactiveUsers = @()
$allUsers = Get-MgUser -All -Property Id, DisplayName, UserPrincipalName, SignInActivity
foreach ($user in $allUsers) {
$lastSignInDate = $user.SignInActivity.LastSignInDateTime
if (-not $lastSignInDate -or ($lastSignInDate -lt $inactiveSince)) {
$inactiveUsers += [PSCustomObject]@{
"User Principal Name" = $user.UserPrincipalName
"Last Sign-in" = if ($lastSignInDate) { $lastSignInDate } else { "Never Signed In" }
}
}
}
# Display inactive users in a table format
if ($inactiveUsers.Count -eq 0) {
Write-Host "No inactive users found within the last $daysInactive days."
} else {
$inactiveUsers | Format-Table -AutoSize
}
Here’s why tracking inactive users is beneficial:
You need User.Read.All permissions in Microsoft Graph PowerShell.
Change $daysInactive = 90 to any desired number of days
Some accounts might have been created but never used. These can be flagged for further investigation.
Modify the script to include:
$inactiveUsers | Export-Csv -Path "InactiveUsers.csv" -NoTypeInformation
Tracking inactive users is a key part of security, compliance, and license management in Microsoft 365. Using Microsoft Graph PowerShell, administrators can quickly generate reports on inactive users and take necessary actions. This script provides a simple yet powerful way to monitor user activity and optimize your Microsoft 365 environment.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex