Guest users are essential for collaboration in Microsoft 365, but over time, many external accounts become inactive and forgotten.
These stale guest accounts can:
👉 In this guide, you’ll learn how to detect inactive Microsoft 365 guest users using Graph PowerShell, export reports, and improve your Entra ID hygiene.
By the end of this article, you’ll be able to:
Install-Module Microsoft.Graph -Scope CurrentUser
The following permissions are required:
Admin consent may be required.
This script relies on the signInActivity property to determine inactivity.
The signInActivity property is available only in:
✅ Supported Licenses
❌ Limited or Unavailable In
⚠️ Important Notes
Connect-MgGraph -Scopes "User.Read.All","AuditLog.Read.All","Directory.Read.All"
Get-MgUser -Filter "userType eq 'Guest'" -All |
Select-Object DisplayName, UserPrincipalName
This script identifies guest users who haven’t signed in for the last 90 days.
# Define inactivity threshold$
DaysInactive = 90
$ThresholdDate = (Get-Date).AddDays(-$DaysInactive)
# Retrieve guest users with sign-in activity
$Guests = Get-MgUser -Filter "userType eq 'Guest'" -Property `
DisplayName,
UserPrincipalName,
SignInActivity -All
# Find inactive guests
$InactiveGuests = $Guests | Where-Object {
$_.SignInActivity.LastSuccessfulSignInDateTime -lt $ThresholdDate
}
# Display results
$InactiveGuests | Select-Object `
DisplayName,
UserPrincipalName,
@{Name="LastSignIn";Expression={$_.SignInActivity.LastSuccessfulSignInDateTime}}
Sample Output
| DisplayName | UserPrincipalName | LastSignIn |
| John Vendor | john_vendor@gmail.com | 2025-11-10 |
| HR Consultant | hrconsultant@external.com | 2025-10-01 |
Admins often need reports for:
$InactiveGuests | Select-Object `
DisplayName,
UserPrincipalName,
@{Name="LastSignIn";Expression={$_.SignInActivity.LastSuccessfulSignInDateTime}} |
Export-Csv "Inactive_Guest_Users_Report.csv" -NoTypeInformation
Write-Host "✅ Report exported successfully!"
This is extremely useful for identifying:
$NeverSignedIn = $Guests | Where-Object {
-not $_.SignInActivity.LastSuccessfulSignInDateTime
}
$NeverSignedIn | Select-Object `
DisplayName,
UserPrincipalName
Old guest accounts are common targets for attackers.
👉 Removing inactive accounts improves security posture.
Many organizations require:
This script helps identify stale accounts quickly.
Consultants and vendors often retain access long after projects end.
👉 Detect and clean up outdated access.
Too many inactive guest users:
powershell.exe -File "InactiveGuestUsers.ps1"
Use Task Scheduler to automate execution.
$CriticalGuests = $InactiveGuests | Where-Object {
$_.SignInActivity.LastSuccessfulSignInDateTime -lt (Get-Date).AddDays(-180)
}
if ($CriticalGuests) {
Write-Host "⚠️ Guests inactive for 180+ days detected!"
}
Visualize:
| Error | Cause | Solution |
| signInActivity property is empty |
|
|
| Insufficient privileges | Insufficient privileges to complete the operation | Connect-MgGraph -Scopes "AuditLog.Read.All","User.Read.All" Admin consent may be required. |
| Property signInActivity not found | Missing property retrieval. | Ensure: -Property SignInActivity is included in Get-MgUser. |
| Slow performance in large tenants | Retrieving all guest users. | Filter properties and export results incrementally. |
| Scenario | Benefit |
| Security cleanup | Reduce attack surface |
| Compliance audits | Identify stale access |
| Vendor governance | Remove unused external accounts |
| Directory hygiene | Clean Entra ID environment |
Inactive guest accounts are one of the most overlooked security risks in Microsoft 365 environments.
Using Graph PowerShell, you can:
👉 Regular guest user reviews should be part of every Microsoft 365 governance strategy.
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