Skip to content

New-MgmtGraphUserMailFolder

MgmtGraph: Provisions a new mail folder in a user's mailbox

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

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

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

    [switch]$Hidden
)

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

        if ($Hidden) { $params.Add('IsHidden', $true) }

        $folder = New-MgUserMailFolder @params
        
        $result = [PSCustomObject]@{
            UserId      = $Identity
            DisplayName = $DisplayName
            Id          = $folder.Id
            Status      = "MailFolderCreated"
            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 display name for the new mail folder.

Off

Optional. If set to $true, the mail folder will be hidden from the user interface.

An interactive directory of PowerShell scripts.