Skip to content

Get-Mailbox-Html

Exchange Online: HTML report of mailboxes

#Requires -Version 5.1

[CmdletBinding()]
Param(
    [switch]$InactiveMailboxOnly,
    [switch]$IncludeInactiveMailbox,
    [switch]$ExcludeResources
)

Process {
    try {
        [string[]]$Properties = @('DisplayName','WindowsEmailAddress','IsInactiveMailbox','IsResource','ArchiveStatus','UserPrincipalName')

        if ($InactiveMailboxOnly) {
            $boxes = Get-Mailbox -InactiveMailboxOnly -SortBy DisplayName -ErrorAction Stop | Select-Object $Properties
        }
        elseif ($IncludeInactiveMailbox) {
            $boxes = Get-Mailbox -IncludeInactiveMailbox -SortBy DisplayName -ErrorAction Stop | Select-Object $Properties
        }
        else {
            $boxes = Get-Mailbox -SortBy DisplayName -ErrorAction Stop | Select-Object $Properties
        }

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

        if ($ExcludeResources) {
            $boxes = $boxes | Where-Object -Property IsResource -EQ $false
        }

        Write-Output ($boxes | ConvertTo-Html -Fragment)
    }
    catch { throw }
}
Off

Include only inactive mailboxes in the results

Off

Include inactive mailboxes in the results

Off

Exclude resource mailboxes from the results

An interactive directory of PowerShell scripts.