Skip to content

Get-MgmtGraphUserDetail

MgmtGraph: Audits all properties of a specific Microsoft Graph user

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

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

Process {
    try {
        $user = Get-MgUser -UserId $Identity -Property "*" -ErrorAction SilentlyContinue
        
        if (-not $user) {
            $user = Get-MgUser -Filter "displayName eq '$Identity'" -Property "*" -ErrorAction Stop
        }

        if (-not $user) {
            throw "User '$Identity' not found."
        }

        # Return the first match if multiple are found via display name
        $results = foreach ($u in $user) {
            $u | Select-Object *
        }

        Write-Output $results
    }
    catch {
        throw
    }
}

Specifies the UserPrincipalName, DisplayName, or ID of the user to retrieve.

An interactive directory of PowerShell scripts.