Remove-MgmtGraphUserMailFolder
MgmtGraph: Deletes a mail folder from 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]$MailFolderId
)
Process {
try {
$params = @{
'UserId' = $Identity
'MailFolderId' = $MailFolderId
'Confirm' = $false
'ErrorAction' = 'Stop'
}
Remove-MgUserMailFolder @params
$result = [PSCustomObject]@{
UserId = $Identity
MailFolderId = $MailFolderId
Action = "MailFolderRemoved"
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 remove.