Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from KelvinTegelaar:master #13

Merged
merged 16 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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