Skip to content

Set-MailboxArchive

Exchange Online: Enables or disables the archive mailbox

#Requires -Version 5.1

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

Process {
    try {
        $box = Get-Mailbox -Identity $MailboxId -ErrorAction Stop
        if ($null -eq $box) {
            throw "Mailbox not found"
        }
        if ($Enable) {
            $null = Enable-Mailbox -Identity $MailboxId -Archive -Confirm:$false -ErrorAction Stop
        }
        else {
            $null = Disable-Mailbox -Identity $MailboxId -Archive -Confirm:$false -ErrorAction Stop
        }
        $result = Get-Mailbox -Identity $MailboxId -ErrorAction Stop | Select-Object ArchiveStatus, UserPrincipalName, DisplayName, WindowsEmailAddress
        $result | ForEach-Object {
            $_ | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force
        }
    }
    catch { throw }
}

Alias, Display name, Distinguished name, SamAccountName, Guid or user principal name of the mailbox

Off

Enables the archive mailbox. If not specified, disables the archive.

An interactive directory of PowerShell scripts.