-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathSet-CIPPDBCacheCASMailboxes.ps1
More file actions
38 lines (31 loc) · 1.38 KB
/
Set-CIPPDBCacheCASMailboxes.ps1
File metadata and controls
38 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function Set-CIPPDBCacheCASMailboxes {
<#
.SYNOPSIS
Caches all CAS mailboxes for a tenant
.PARAMETER TenantFilter
The tenant to cache CAS mailboxes for
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$TenantFilter
)
try {
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Caching CAS mailboxes' -sev Debug
# Use Generic List for better memory efficiency with large datasets
$CASMailboxList = [System.Collections.Generic.List[PSObject]]::new()
$CASMailboxesResponse = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-CasMailbox'
foreach ($Mailbox in $CASMailboxesResponse) {
$CASMailboxList.Add($Mailbox)
}
Add-CIPPDbItem -TenantFilter $TenantFilter -Type 'CASMailbox' -Data $CASMailboxList.ToArray()
Add-CIPPDbItem -TenantFilter $TenantFilter -Type 'CASMailbox' -Data @{ Count = $CASMailboxList.Count } -Count
$CASMailboxesResponse = $null
$CASMailboxList.Clear()
$CASMailboxList = $null
[System.GC]::Collect()
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message 'Cached CAS mailboxes successfully' -sev Debug
} catch {
Write-LogMessage -API 'CIPPDBCache' -tenant $TenantFilter -message "Failed to cache CAS mailboxes: $($_.Exception.Message)" -sev Error
}
}