Skip to content

Commit

Permalink
Merge pull request #20 from KelvinTegelaar/master
Browse files Browse the repository at this point in the history
[pull] master from KelvinTegelaar:master
  • Loading branch information
pull[bot] authored Jan 22, 2024
2 parents 554c05a + b209472 commit 784d7ac
Show file tree
Hide file tree
Showing 6 changed files with 12,477 additions and 2,829 deletions.
5,084 changes: 4,146 additions & 938 deletions ConversionTable.csv

Large diffs are not rendered by default.

5,084 changes: 4,146 additions & 938 deletions Modules/CIPPCore/Public/ConversionTable.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,49 @@ function Invoke-CIPPStandardEnableOnlineArchiving {
Internal
#>
param($Tenant, $Settings)
$MailboxesNoArchive = (New-ExoRequest -tenantid $tenant -cmdlet 'get-mailbox' -cmdparams @{ Filter = 'ArchiveGuid -Eq "00000000-0000-0000-0000-000000000000" -AND RecipientTypeDetails -Eq "UserMailbox"' })

$MailboxPlans = @( 'ExchangeOnline', 'ExchangeOnlineEnterprise' )
$MailboxesNoArchive = $MailboxPlans | ForEach-Object {
New-ExoRequest -tenantid $Tenant -cmdlet 'Get-Mailbox' -cmdparams @{ MailboxPlan = $_; Filter = 'ArchiveGuid -Eq "00000000-0000-0000-0000-000000000000" -AND RecipientTypeDetails -Eq "UserMailbox"' }
Write-Host "Getting mailboxes without Online Archiving for plan $_"
}

If ($Settings.remediate) {


try {
$MailboxesNoArchive | ForEach-Object {
(New-ExoRequest -tenantid $tenant -cmdlet 'enable-Mailbox' -cmdparams @{ Identity = $_.UserPrincipalName; Archive = $true })
if ($null -eq $MailboxesNoArchive) {
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Online Archiving already enabled for all accounts' -sev Info
} else {
try {
$SuccessCounter = 0
$MailboxesNoArchive | ForEach-Object {
try {
New-ExoRequest -tenantid $Tenant -cmdlet 'Enable-Mailbox' -cmdparams @{ Identity = $_.UserPrincipalName; Archive = $true } | Out-Null
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Enabled Online Archiving for $($_.UserPrincipalName)" -sev Info
$SuccessCounter++
} catch {
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to Enable Online Archiving for $($_.UserPrincipalName). Error: $($_.exception.message)" -sev Error
}
}
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Enabled Online Archiving for $SuccessCounter accounts" -sev Info

} catch {
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to Enable Online Archiving for all accounts. Error: $($_.exception.message)" -sev Error
}
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Enabled Online Archiving for all accounts' -sev Info

} catch {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to Enable Online Archiving for all accounts Error: $($_.exception.message)" -sev Error
}

}

if ($Settings.alert) {

if ($MailboxesNoArchive) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Mailboxes without Online Archiving: $($MailboxesNoArchive.count)" -sev Alert
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Mailboxes without Online Archiving: $($MailboxesNoArchive.Count)" -sev Alert
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'All mailboxes have Online Archiving enabled' -sev Info
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'All mailboxes have Online Archiving enabled' -sev Info
}
}

if ($Settings.report) {
$filtered = $MailboxesNoArchive | Select-Object -Property UserPrincipalName, Archive
Add-CIPPBPAField -FieldName 'EnableOnlineArchiving' -FieldValue $MailboxesNoArchive -StoreAs json -Tenant $tenant
$filtered = $MailboxesNoArchive | Select-Object -Property UserPrincipalName, ArchiveGuid
Add-CIPPBPAField -FieldName 'EnableOnlineArchiving' -FieldValue $filtered -StoreAs json -Tenant $Tenant
}
}
Loading

0 comments on commit 784d7ac

Please sign in to comment.