All scripts
Governance 548
Get-EntraGuestUserReport
Lists every guest account in Entra ID with when it was created, its status, and which groups it belongs to, so guest sprawl is visible in one report instead of scattered across group memberships.
Get-EntraGuestUserReport.ps1
<#
.SYNOPSIS
Reports all guest accounts in Entra ID.
.DESCRIPTION
Lists every guest user with creation date, invitation status and
group memberships, so guest account sprawl is visible in a single
report instead of scattered across individual group membership lists.
.EXAMPLE
.\Get-EntraGuestUserReport.ps1
.NOTES
Requires Microsoft.Graph.Users and Microsoft.Graph.Groups with an
active Connect-MgGraph session.
.AUTHOR
Shehryar Hassan
#>
$guests = Get-MgUser -Filter "userType eq 'Guest'" -All -Property Id,DisplayName,Mail,CreatedDateTime,ExternalUserState
$report = foreach ($guest in $guests) {
$groups = Get-MgUserMemberOf -UserId $guest.Id | ForEach-Object { $_.AdditionalProperties.displayName }
[pscustomobject]@{
DisplayName = $guest.DisplayName
Email = $guest.Mail
Created = $guest.CreatedDateTime
State = $guest.ExternalUserState
GroupCount = $groups.Count
}
}
$report | Sort-Object Created | Format-Table -AutoSize
Write-Host "$($guests.Count) guest account(s) found" -ForegroundColor Cyan
Read it before you run it, and test in a safe tenant first.