Skip to content

Set-MgmtGraphGroup

MgmtGraph: Updates Microsoft Graph group properties

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

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

    [string]$DisplayName,

    [string]$Description,

    [ValidateSet('Public', 'Private')]
    [string]$Visibility,

    [string]$MailNickname
)

Process {
    try {
        $params = @{
            'GroupId'     = $Identity
            'Confirm'     = $false
            'ErrorAction' = 'Stop'
        }

        if ($PSBoundParameters.ContainsKey('DisplayName')) { $params.Add('DisplayName', $DisplayName) }
        if ($PSBoundParameters.ContainsKey('Description')) { $params.Add('Description', $Description) }
        if ($PSBoundParameters.ContainsKey('Visibility')) { $params.Add('Visibility', $Visibility) }
        if ($PSBoundParameters.ContainsKey('MailNickname')) { $params.Add('MailNickname', $MailNickname) }

        if ($params.Count -gt 3) {
            Update-MgGroup @params
            
            $result = [PSCustomObject]@{
                GroupId   = $Identity
                Action    = "GroupUpdated"
                Status    = "Success"
                Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
            Write-Output $result
        }
        else {
            Write-Warning "No properties specified to update for group '$Identity'."
        }
    }
    catch {
        throw
    }
}

Specifies the ID of the group to update.

Optional. Specifies the new display name.

Optional. Specifies the new description.

Optional. Specifies the new visibility level (Public, Private).

Optional. Specifies the new mail alias.

An interactive directory of PowerShell scripts.