Security · 2 tools
Guest users, invitation state and last sign-in
Summary
Lists every guest with where they came from, whether they accepted the invitation and when they last signed in, so you can clean up stale guests before an audit or a tenant migration.
Implementation
Choose your tool. Your choice is remembered on other samples.
Connect-MgGraph -Scopes User.Read.All, AuditLog.Read.All -NoWelcome
Get-MgUser -All -Filter "userType eq 'Guest'" `
-Property DisplayName, Mail, UserPrincipalName, CreatedDateTime, ExternalUserState, SignInActivity, CreationType |
Select-Object DisplayName, Mail, CreatedDateTime, ExternalUserState, CreationType,
@{ n = "Domain"; e = { ($_.Mail -split "@")[-1] } },
@{ n = "LastSignIn"; e = { $_.SignInActivity.LastSignInDateTime } } |
Sort-Object LastSignIn |
Export-Csv .\guests.csv -NoTypeInformationm365 login
m365 entra user list --properties "displayName,mail,userType,createdDateTime,externalUserState" --output json |
ConvertFrom-Json | Where-Object userType -eq "Guest" |
Export-Csv .\guests.csv -NoTypeInformationPrerequisites
- Graph scopes User.Read.All and AuditLog.Read.All
Output
CSV of guests with invitation state and last sign-in.
Contributors
| Author | Role |
|---|---|
| Priyanshu Upadhyay | Solution Architect, Microsoft 365 and Azure |
InnovaticT