Skip to content

Set-MgmtGraphUserMailboxSetting

MgmtGraph: Updates mailbox settings for a Microsoft Graph user

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

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

    [string]$DateFormat,

    [string]$TimeFormat,

    [string]$TimeZone
)

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

        if ($PSBoundParameters.ContainsKey('DateFormat')) { $params.Add('DateFormat', $DateFormat) }
        if ($PSBoundParameters.ContainsKey('TimeFormat')) { $params.Add('TimeFormat', $TimeFormat) }
        if ($PSBoundParameters.ContainsKey('TimeZone')) { $params.Add('TimeZone', $TimeZone) }

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

Specifies the UserPrincipalName or ID of the user to update.

Optional. Specifies the preferred date format (e.g., "yyyy-MM-dd").

Optional. Specifies the preferred time format (e.g., "HH:mm").

Optional. Specifies the preferred time zone string (e.g., "W. Europe Standard Time").

An interactive directory of PowerShell scripts.