Entra ID· 1 min read

Find inactive guest users with Microsoft Graph PowerShell

A practical script to list Entra ID guest accounts that haven't signed in for 90 days — plus the raw Graph API call behind it.

Guest accounts are easy to create and easy to forget. A year after a project ends, the external consultant can still open your Teams and SharePoint sites. In this post we’ll build a small report of guests who haven’t signed in for 90 days, so you can review and clean them up.

Before you start: reading sign-in activity requires a Microsoft Entra ID P1 (or higher) licence in the tenant, and the AuditLog.Read.All permission.

1. Connect to Microsoft Graph

Install the module once, then connect with the two read-only scopes we need:

# Install once (current user only)
Install-Module Microsoft.Graph.Users -Scope CurrentUser

# Connect with read-only permissions
Connect-MgGraph -Scopes 'User.Read.All', 'AuditLog.Read.All' -NoWelcome

2. Get all guests with their last sign-in

The signInActivity property isn’t returned by default, so we ask for it explicitly with -Property:

$cutoff = (Get-Date).AddDays(-90)

$guests = Get-MgUser -All `
    -Filter "userType eq 'Guest'" `
    -Property Id, DisplayName, Mail, CreatedDateTime, SignInActivity

$inactive = $guests | Where-Object {
    $last = $_.SignInActivity.LastSuccessfulSignInDateTime
    # Never signed in, or not since the cutoff
    -not $last -or $last -lt $cutoff
} | Select-Object DisplayName, Mail, CreatedDateTime,
    @{ Name = 'LastSignIn'; Expression = { $_.SignInActivity.LastSuccessfulSignInDateTime } }

$inactive | Sort-Object LastSignIn | Format-Table -AutoSize
"Found $($inactive.Count) inactive guests out of $($guests.Count)."

Export the list for a review with the business owners:

$inactive | Export-Csv -Path .\inactive-guests.csv -NoTypeInformation -Encoding utf8

3. The same thing with the Graph API

Under the hood, the cmdlet calls this endpoint. You can try it directly in Graph Explorer:

GET https://graph.microsoft.com/v1.0/users?$filter=userType eq 'Guest'&$select=displayName,mail,createdDateTime,signInActivity

A trimmed response looks like this:

{
  "value": [
    {
      "displayName": "Jane Consultant",
      "mail": "jane@contoso.com",
      "createdDateTime": "2025-02-11T09:14:03Z",
      "signInActivity": {
        "lastSignInDateTime": "2025-06-30T13:02:44Z",
        "lastSuccessfulSignInDateTime": "2025-06-30T13:02:44Z"
      }
    }
  ]
}

4. What to do with the list

Situation Suggested action
Guest never accepted the invitation Delete the account
Project has ended Confirm with the owner, then delete
Still needed, but rarely used Keep — and set up an access review

Rather than running this by hand forever, consider Access reviews in Entra ID Governance to make guest clean-up a recurring, owner-driven process.

Wrap-up

  • Use -Property SignInActivity — it isn’t returned by default.
  • Prefer lastSuccessfulSignInDateTime over lastSignInDateTime, which also counts failed attempts.
  • Treat the report as input for a conversation with owners, not as an automatic delete list.

Happy cleaning! 🧹