Skip to content

Get-EXOMailboxes-Query

Exchange Online Management: Query-format list of mailboxes

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [switch]$Archive,
    [switch]$InactiveMailboxOnly,
    [switch]$IncludeInactiveMailbox,
    [switch]$SoftDeletedMailbox
)

Process {
    try {
        [hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'; 'Archive' = $Archive; 'InactiveMailboxOnly' = $InactiveMailboxOnly; 'IncludeInactiveMailbox' = $IncludeInactiveMailbox; 'SoftDeletedMailbox' = $SoftDeletedMailbox}

        $boxes = Get-EXOMailbox @cmdArgs | Select-Object DisplayName, Name | Sort-Object DisplayName

        if ($null -eq $boxes -or $boxes.Count -eq 0) {
            Write-Output "No mailboxes found"
            return
        }

        foreach ($itm in $boxes) {
            [PSCustomObject]@{
                Timestamp    = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
                Value        = $itm.Name
                DisplayValue = $itm.DisplayName
            }
        }
    }
    catch { throw }
}
Off

Returns only mailboxes that have an archive mailbox

Off

Returns only inactive mailboxes

Off

Include inactive mailboxes in the results

Off

Include soft-deleted mailboxes in the results

An interactive directory of PowerShell scripts.