Get-MgUserSponsor is a Microsoft Graph PowerShell cmdlet used to retrieve the sponsor(s) assigned to a user in Microsoft Entra ID (Azure AD).
A Sponsor is typically assigned to Guest users (B2B users) and represents the internal employee responsible for that guestβs access and lifecycle within the tenant.
This cmdlet retrieves the directory object(s) configured as sponsors for a specific user.
In most real-world scenarios, this cmdlet is used for:
Try the M365Corner Microsoft 365 Reporting Tool β your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Guest user sprawl is a real governance challenge in many organizations.
Sponsors help answer critical questions:
Using Get-MgUserSponsor, administrators can:
For security-conscious environments, sponsor visibility is essential.
Before using Get-MgUserSponsor, ensure:
Install Microsoft Graph (if needed)
Install-Module Microsoft.Graph -Scope CurrentUser
Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All","Directory.Read.All"
To use Get-MgUserSponsor, the following permissions are required:
Delegated Permissions
Application Permissions (For automation)
β οΈ Admin consent is required for Directory-level permissions.
Syntax
Get-MgUserSponsor -UserId <String>
Parameter Explanation
| Parameter | Description |
|---|---|
| -UserId | The User Principal Name (UPN) or Object ID of the user |
You can pass:
Basic usage:
Get-MgUserSponsor -UserId "guestuser@domain.com"
This returns the sponsor directory object(s).
To get full details (Display Name, UPN), you must query the sponsor using Get-MgUser.
Get-MgUserSponsor -UserId "guestuser@domain.com"
Explanation
$sponsor = Get-MgUserSponsor -UserId "guestuser@domain.com"
Get-MgUser -UserId $sponsor.Id
This helps identify:
This script:
Write-Host "Fetching all Guest Users..." -ForegroundColor Cyan
# Step 1: Get all Guest users
$GuestUsers = Get-MgUser -Filter "userType eq 'Guest'" -All
# Store results
$SponsorReport = @()
# Step 2: Loop through each guest user
foreach ($guest in $GuestUsers) {
Write-Host "Processing Guest: $($guest.DisplayName)" -ForegroundColor Yellow
try {
# Step 3: Get sponsor ID(s)
$sponsors = Get-MgUserSponsor -UserId $guest.Id
foreach ($sponsor in $sponsors) {
# Step 4: Fetch sponsor details
$sponsorDetails = Get-MgUser -UserId $sponsor.Id
# Step 5: Add record to report
$SponsorReport += [PSCustomObject]@{
GuestDisplayName = $guest.DisplayName
GuestUPN = $guest.UserPrincipalName
SponsorDisplayName = $sponsorDetails.DisplayName
SponsorUPN = $sponsorDetails.UserPrincipalName
}
# Output to console
Write-Host " Sponsor Found: $($sponsorDetails.DisplayName)" -ForegroundColor Green
}
}
catch {
Write-Warning "No sponsor found for guest: $($guest.UserPrincipalName)"
}
}
# Step 6: Export report
$SponsorReport | Export-Csv "GuestSponsorReport.csv" -NoTypeInformation
Write-Host "`nGuest Sponsor Report Exported Successfully!" -ForegroundColor Cyan
Write-Host "File: GuestSponsorReport.csv"
What This Script Does
Sample Output (CSV) will contain the following headers and values
| GuestDisplayName | GuestUPN | SponsorDisplayName | SponsorUPN |
|---|
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.
© Created and Maintained by LEARNIT WELL SOLUTIONS. All Rights Reserved.