Skip to content

Set-ExchangeMailboxArchiveConfig

Exchange: Configures archive settings for a mailbox

#Requires -Version 5.1

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

    [Parameter(Mandatory = $true)]
    [bool]$Archive,

    [string]$ArchiveDatabase,

    [string]$ArchiveName
)

Process {
    try {
        if ($Archive) {
            $params = @{
                'Identity'    = $Identity
                'Archive'     = $true
                'Confirm'     = $false
                'ErrorAction' = 'Stop'
            }
            if ($ArchiveDatabase) { $params.Add('ArchiveDatabase', $ArchiveDatabase) }
            if ($ArchiveName) { $params.Add('ArchiveName', $ArchiveName) }

            Enable-Mailbox @params
        }
        else {
            Disable-Mailbox -Identity $Identity -Archive -Confirm:$false -ErrorAction Stop
        }

        $mailbox = Get-Mailbox -Identity $Identity -ErrorAction Stop
        $result = [PSCustomObject]@{
            Identity     = $Identity
            ArchiveState = $mailbox.ArchiveState
            ArchiveName  = $mailbox.ArchiveName
            Action       = "ArchiveConfigUpdated"
            Status       = "Success"
            Timestamp    = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the Identity of the mailbox (Alias, Email, GUID, etc.).

Specifies whether the archive should be enabled ($true) or disabled ($false).

Optional. Specifies the Exchange database to hold the archive mailbox (On-Premises only).

Optional. Specifies a custom name for the archive mailbox.

An interactive directory of PowerShell scripts.