|
| 1 | +function Invoke-CIPPStandardAutoArchiveMailbox { |
| 2 | + <# |
| 3 | + .FUNCTIONALITY |
| 4 | + Internal |
| 5 | + .COMPONENT |
| 6 | + (APIName) AutoArchiveMailbox |
| 7 | + .SYNOPSIS |
| 8 | + (Label) Set auto enable archive mailbox state |
| 9 | + .DESCRIPTION |
| 10 | + (Helptext) Enables or disables the tenant policy that automatically provisions an archive mailbox when a user's primary mailbox reaches 90% of its quota. |
| 11 | + (DocsDescription) Enables or disables the tenant policy that automatically provisions an archive mailbox when a user's primary mailbox reaches 90% of its quota. This is separate from auto-archiving thresholds and does not enable archives for all users immediately. |
| 12 | + .NOTES |
| 13 | + CAT |
| 14 | + Exchange Standards |
| 15 | + TAG |
| 16 | + EXECUTIVETEXT |
| 17 | + Automatically provisions archive mailboxes only when users reach 90% of their mailbox capacity, reducing manual intervention and preventing mailbox quota issues without enabling archives for everyone. |
| 18 | + ADDEDCOMPONENT |
| 19 | + {"type":"autoComplete","multiple":false,"creatable":false,"label":"Select value","name":"standards.AutoArchiveMailbox.state","options":[{"label":"Enabled","value":"enabled"},{"label":"Disabled","value":"disabled"}]} |
| 20 | + IMPACT |
| 21 | + Low Impact |
| 22 | + ADDEDDATE |
| 23 | + 2026-01-16 |
| 24 | + POWERSHELLEQUIVALENT |
| 25 | + Set-OrganizationConfig -AutoEnableArchiveMailbox \$true\|\$false |
| 26 | + RECOMMENDEDBY |
| 27 | + UPDATECOMMENTBLOCK |
| 28 | + Run the Tools\Update-StandardsComments.ps1 script to update this comment block |
| 29 | + .LINK |
| 30 | + https://docs.cipp.app/user-documentation/tenant/standards/list-standards |
| 31 | + #> |
| 32 | + |
| 33 | + param($Tenant, $Settings) |
| 34 | + $TestResult = Test-CIPPStandardLicense -StandardName 'AutoArchiveMailbox' -TenantFilter $Tenant -RequiredCapabilities @('EXCHANGE_S_STANDARD', 'EXCHANGE_S_ENTERPRISE', 'EXCHANGE_S_STANDARD_GOV', 'EXCHANGE_S_ENTERPRISE_GOV', 'EXCHANGE_LITE') |
| 35 | + |
| 36 | + if ($TestResult -eq $false) { |
| 37 | + Write-Host "We're exiting as the correct license is not present for this standard." |
| 38 | + return $true |
| 39 | + } |
| 40 | + |
| 41 | + $StateValue = $Settings.state.value ?? $Settings.state |
| 42 | + |
| 43 | + if ([string]::IsNullOrWhiteSpace($StateValue)) { |
| 44 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message 'AutoArchiveMailbox: Invalid state parameter set' -Sev Error |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + $DesiredState = $StateValue -eq 'enabled' |
| 49 | + |
| 50 | + try { |
| 51 | + $CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-OrganizationConfig' -Select 'AutoEnableArchiveMailbox').AutoEnableArchiveMailbox |
| 52 | + } catch { |
| 53 | + $ErrorMessage = Get-CippException -Exception $_ |
| 54 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get the AutoArchiveMailbox state for $Tenant. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage |
| 55 | + return |
| 56 | + } |
| 57 | + |
| 58 | + $CorrectState = $CurrentState -eq $DesiredState |
| 59 | + |
| 60 | + $ExpectedValue = [PSCustomObject]@{ |
| 61 | + AutoEnableArchiveMailbox = $DesiredState |
| 62 | + } |
| 63 | + $CurrentValue = [PSCustomObject]@{ |
| 64 | + AutoEnableArchiveMailbox = $CurrentState |
| 65 | + } |
| 66 | + |
| 67 | + if ($Settings.remediate -eq $true) { |
| 68 | + Write-Host 'Time to remediate' |
| 69 | + |
| 70 | + if ($CorrectState) { |
| 71 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Auto enable archive mailbox is already set to $StateValue." -Sev Info |
| 72 | + } else { |
| 73 | + try { |
| 74 | + New-ExoRequest -tenantid $Tenant -cmdlet 'Set-OrganizationConfig' -cmdParams @{ AutoEnableArchiveMailbox = $DesiredState } |
| 75 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Auto enable archive mailbox has been set to $StateValue." -Sev Info |
| 76 | + } catch { |
| 77 | + $ErrorMessage = Get-CippException -Exception $_ |
| 78 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Failed to set auto enable archive mailbox to $StateValue. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + if ($Settings.alert -eq $true) { |
| 84 | + if ($CorrectState) { |
| 85 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Auto enable archive mailbox is correctly set to $StateValue." -Sev Info |
| 86 | + } else { |
| 87 | + Write-StandardsAlert -message "Auto enable archive mailbox is set to $CurrentState but should be $DesiredState." -object @{ CurrentState = $CurrentState; DesiredState = $DesiredState } -tenant $Tenant -standardName 'AutoArchiveMailbox' -standardId $Settings.standardId |
| 88 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Auto enable archive mailbox is set to $CurrentState but should be $DesiredState." -Sev Info |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + if ($Settings.report -eq $true) { |
| 93 | + Set-CIPPStandardsCompareField -FieldName 'standards.AutoArchiveMailbox' -CurrentValue $CurrentValue -ExpectedValue $ExpectedValue -TenantFilter $Tenant |
| 94 | + Add-CIPPBPAField -FieldName 'AutoArchiveMailbox' -FieldValue $CurrentState -StoreAs bool -Tenant $Tenant |
| 95 | + } |
| 96 | +} |
0 commit comments