File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Modules/CIPPCore/Public/Alerts Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ function Get-CIPPAlertMXRecordChanged {
2+ <#
3+ . FUNCTIONALITY
4+ Entrypoint
5+ #>
6+ [CmdletBinding ()]
7+ param (
8+ [Parameter (Mandatory )]
9+ $TenantFilter ,
10+ [Alias (' input' )]
11+ $InputValue
12+ )
13+
14+ try {
15+ $DomainData = Get-CIPPDomainAnalyser - TenantFilter $TenantFilter
16+ $CacheTable = Get-CippTable - tablename ' CacheMxRecords'
17+ $PreviousResults = Get-CIPPAzDataTableEntity @CacheTable - Filter " PartitionKey eq '$TenantFilter '"
18+
19+ $ChangedDomains = foreach ($Domain in $DomainData ) {
20+ $PreviousDomain = $PreviousResults | Where-Object { $_.Domain -eq $Domain.Domain }
21+ if ($PreviousDomain -and $PreviousDomain.ActualMXRecords -ne $Domain.ActualMXRecords ) {
22+ " $ ( $Domain.Domain ) : MX records changed from [$ ( $PreviousDomain.ActualMXRecords -join ' , ' ) ] to [$ ( $Domain.ActualMXRecords -join ' , ' ) ]"
23+ }
24+ }
25+
26+ if ($ChangedDomains ) {
27+ Write-AlertTrace - cmdletName $MyInvocation.MyCommand - tenantFilter $TenantFilter - data $ChangedDomains
28+ }
29+
30+ # Update cache with current data
31+ foreach ($Domain in $DomainData ) {
32+ $CacheEntity = @ {
33+ PartitionKey = $TenantFilter
34+ RowKey = $Domain.Domain
35+ Domain = $Domain.Domain
36+ ActualMXRecords = $Domain.ActualMXRecords
37+ LastRefresh = $Domain.LastRefresh
38+ MailProvider = $Domain.MailProvider
39+ }
40+ Add-CIPPAzDataTableEntity @CacheTable - Entity $CacheEntity - Force
41+ }
42+ } catch {
43+ Write-LogMessage - message " Failed to check MX record changes: $ ( $_.Exception.Message ) " - API ' MX Record Alert' - tenant $TenantFilter - sev Error
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments