Skip to content

Get-MgmtGraphUserSponsor

MgmtGraph: Audits sponsors for a Microsoft Graph guest user

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Users

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $true, Position = 0)]
    [string]$Identity
)

Process {
    try {
        $sponsors = Get-MgUserSponsor -UserId $Identity -All -ErrorAction Stop
        
        $results = foreach ($s in $sponsors) {
            [PSCustomObject]@{
                DisplayName = $s.AdditionalProperties.displayName
                Type        = $s.AdditionalProperties.'@odata.type'.Replace('#microsoft.graph.', '')
                Mail        = $s.AdditionalProperties.mail
                Id          = $s.Id
                Timestamp   = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output ($results | Sort-Object DisplayName)
    }
    catch {
        throw
    }
}

Specifies the UserPrincipalName or ID of the guest user to audit.

An interactive directory of PowerShell scripts.