Skip to content

Get-MailboxDelegation

Exchange Online: Retrieves mailbox delegation settings

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$MailboxId
)

Process {
    try {
        $result = [System.Collections.ArrayList]::new()

        $null = $result.Add([PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; DelegationType = "Send As"; Trustee = "---------------" })
        $sendAs = Get-RecipientPermission -Identity $MailboxId -ErrorAction Stop | Select-Object *
        foreach ($item in $sendAs) {
            $null = $result.Add([PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; DelegationType = "Send As"; Trustee = $item.Trustee })
        }

        $null = $result.Add([PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; DelegationType = "Send On Behalf"; Trustee = "---------------" })
        $sendOnBehalf = Get-Mailbox -Identity $MailboxId -ErrorAction Stop | Select-Object -ExpandProperty GrantSendOnBehalfTo
        foreach ($item in $sendOnBehalf) {
            $null = $result.Add([PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; DelegationType = "Send On Behalf"; Trustee = $item })
        }

        $null = $result.Add([PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; DelegationType = "Full Access"; Trustee = "---------------" })
        $fullAccess = Get-MailboxPermission -Identity $MailboxId -ErrorAction Stop | Select-Object *
        foreach ($item in $fullAccess) {
            $null = $result.Add([PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; DelegationType = "Full Access"; Trustee = $item.User })
        }

        Write-Output $result
    }
    catch { throw }
}

Identity of the mailbox (alias, display name, DN, SAM, GUID, or UPN)

An interactive directory of PowerShell scripts.