Skip to content

Get-MgmtGraphGroupMember

MgmtGraph: Audits members of a Microsoft Graph group

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

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

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

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

Specifies the ID of the group to audit.

An interactive directory of PowerShell scripts.