Skip to content

Get-MgmtGraphGroupPhotoContent

MgmtGraph: Downloads a group profile photo to a file

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

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

    [Parameter(Mandatory = $true, Position = 1)]
    [string]$OutFile
)

Process {
    try {
        Get-MgGroupPhotoContent -GroupId $GroupId -OutFile $OutFile -ErrorAction Stop
        
        $fileInfo = Get-Item -Path $OutFile -ErrorAction SilentlyContinue
        
        $result = [PSCustomObject]@{
            GroupId     = $GroupId
            FilePath    = $OutFile
            SizeInBytes = if ($fileInfo) { $fileInfo.Length } else { $null }
            Downloaded  = [bool]$fileInfo
            Timestamp   = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

The unique identifier of the Microsoft Graph group.

The local file path where the group photo should be saved.

An interactive directory of PowerShell scripts.