Skip to content

Set-MgmtGraphUserMailFolder

MgmtGraph: Updates user mail folder properties

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

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

    [Parameter(Mandatory = $true)]
    [string]$MailFolderId,

    [Parameter(Mandatory = $true)]
    [string]$DisplayName
)

Process {
    try {
        $params = @{
            'UserId'       = $Identity
            'MailFolderId' = $MailFolderId
            'DisplayName'  = $DisplayName
            'Confirm'      = $false
            'ErrorAction'  = 'Stop'
        }

        Update-MgUserMailFolder @params
        
        $result = [PSCustomObject]@{
            UserId       = $Identity
            MailFolderId = $MailFolderId
            DisplayName  = $DisplayName
            Action       = "MailFolderUpdated"
            Status       = "Success"
            Timestamp    = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the UserPrincipalName or ID of the user.

Specifies the ID of the mail folder to update.

Specifies the new display name for the mail folder.

An interactive directory of PowerShell scripts.