Skip to content

Commit 5613ca8

Browse files
committed
fix: dkim standard not enabling dkim sometimes if supportedServices is showing wrong data
1 parent 2fef3bc commit 5613ca8

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAddDKIM.ps1

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ function Invoke-CIPPStandardAddDKIM {
3333
param($Tenant, $Settings)
3434
#$Rerun -Type Standard -Tenant $Tenant -API 'AddDKIM' -Settings $Settings
3535

36-
37-
$AllDomains = (New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/domains?$top=999' -tenantid $Tenant | Where-Object { $_.supportedServices -contains 'Email' -or $_.id -like '*mail.onmicrosoft.com' }).id
38-
$DKIM = (New-ExoRequest -tenantid $tenant -cmdlet 'Get-DkimSigningConfig') | Select-Object Domain, Enabled, Status
36+
$AllDomains = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-AcceptedDomain').DomainName
37+
$DKIM = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-DkimSigningConfig') | Select-Object Domain, Enabled, Status
3938

4039
# List of domains for each way to enable DKIM
4140
$NewDomains = $AllDomains | Where-Object { $DKIM.Domain -notcontains $_ }
@@ -44,10 +43,10 @@ function Invoke-CIPPStandardAddDKIM {
4443
If ($Settings.remediate -eq $true) {
4544

4645
if ($null -eq $NewDomains -and $null -eq $SetDomains) {
47-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'DKIM is already enabled for all available domains.' -sev Info
46+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'DKIM is already enabled for all available domains.' -sev Info
4847
} else {
4948
$ErrorCounter = 0
50-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Trying to enable DKIM for:$($NewDomains -join ', ' ) $($SetDomains.Domain -join ', ')" -sev Info
49+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Trying to enable DKIM for:$($NewDomains -join ', ' ) $($SetDomains.Domain -join ', ')" -sev Info
5150

5251
# New-domains
5352
$Request = $NewDomains | ForEach-Object {
@@ -58,12 +57,12 @@ function Invoke-CIPPStandardAddDKIM {
5857
}
5958
}
6059
}
61-
if ($null -ne $Request) { $BatchResults = New-ExoBulkRequest -tenantid $tenant -cmdletArray @($Request) -useSystemMailbox $true }
60+
if ($null -ne $Request) { $BatchResults = New-ExoBulkRequest -tenantid $Tenant -cmdletArray @($Request) -useSystemMailbox $true }
6261
$BatchResults | ForEach-Object {
6362
if ($_.error) {
6463
$ErrorCounter ++
6564
$ErrorMessage = Get-NormalizedError -Message $_.error
66-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable DKIM. Error: $ErrorMessage" -sev Error
65+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to enable DKIM. Error: $ErrorMessage" -sev Error
6766
}
6867
}
6968

@@ -76,21 +75,21 @@ function Invoke-CIPPStandardAddDKIM {
7675
}
7776
}
7877
}
79-
if ($null -ne $Request) { $BatchResults = New-ExoBulkRequest -tenantid $tenant -cmdletArray @($Request) -useSystemMailbox $true }
78+
if ($null -ne $Request) { $BatchResults = New-ExoBulkRequest -tenantid $Tenant -cmdletArray @($Request) -useSystemMailbox $true }
8079
$BatchResults | ForEach-Object {
8180
if ($_.error) {
8281
$ErrorCounter ++
8382
$ErrorMessage = Get-NormalizedError -Message $_.error
84-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to set DKIM. Error: $ErrorMessage" -sev Error
83+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to set DKIM. Error: $ErrorMessage" -sev Error
8584
}
8685
}
8786

8887
if ($ErrorCounter -eq 0) {
89-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Enabled DKIM for all domains in tenant' -sev Info
88+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Enabled DKIM for all domains in tenant' -sev Info
9089
} elseif ($ErrorCounter -gt 0 -and $ErrorCounter -lt ($NewDomains.Count + $SetDomains.Count)) {
91-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to enable DKIM for some domains in tenant' -sev Error
90+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Failed to enable DKIM for some domains in tenant' -sev Error
9291
} else {
93-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'Failed to enable DKIM for all domains in tenant' -sev Error
92+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'Failed to enable DKIM for all domains in tenant' -sev Error
9493
}
9594
}
9695
}

0 commit comments

Comments
 (0)