Skip to content

Remove-MgmtGraphUserMailFolderChildFolder

MgmtGraph: Deletes a child mail folder

#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]$ChildFolderId
)

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

        Remove-MgUserMailFolderChildFolder @params
        
        $result = [PSCustomObject]@{
            UserId        = $Identity
            ParentId      = $MailFolderId
            ChildFolderId = $ChildFolderId
            Action        = "ChildFolderRemoved"
            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 parent mail folder.

Specifies the ID of the child folder to remove.

An interactive directory of PowerShell scripts.