Skip to content

Commit 323e64d

Browse files
committed
feat: Add Invoke-CIPPStandardEXODirectSend function to manage Direct Send state
1 parent 158a175 commit 323e64d

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
function Invoke-CIPPStandardEXODirectSend {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) EXODirectSend
7+
.SYNOPSIS
8+
(Label) Set Direct Send state
9+
.DESCRIPTION
10+
(Helptext) Sets the state of Direct Send in Exchange Online. Direct Send allows applications to send emails directly to Exchange Online mailboxes as the tenants domains, without requiring authentication.
11+
(DocsDescription) Controls whether applications can use Direct Send to send emails directly to Exchange Online mailboxes as the tenants domains, without requiring authentication. A detailed explanation from Microsoft can be found [here.](https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-microsoft-365-or-office-365)
12+
.NOTES
13+
CAT
14+
Exchange Standards
15+
TAG
16+
ADDEDCOMPONENT
17+
{"type":"autoComplete","multiple":false,"creatable":false,"label":"Select value","name":"standards.EXODirectSend.state","options":[{"label":"Enabled","value":"enabled"},{"label":"Disabled","value":"disabled"}]}
18+
IMPACT
19+
Medium Impact
20+
ADDEDDATE
21+
2025-05-28
22+
POWERSHELLEQUIVALENT
23+
Set-OrganizationConfig -RejectDirectSend \$true/\$false
24+
RECOMMENDEDBY
25+
UPDATECOMMENTBLOCK
26+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
27+
.LINK
28+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards
29+
#>
30+
31+
param ($Tenant, $Settings)
32+
33+
34+
# Get current organization config
35+
try {
36+
$CurrentConfig = (New-ExoRequest -TenantID $Tenant -cmdlet 'Get-OrganizationConfig' -Select 'RejectDirectSend').RejectDirectSend
37+
} catch {
38+
$ErrorMessage = Get-CippException -Exception $_
39+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to retrieve current Direct Send configuration: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
40+
return
41+
}
42+
43+
# Determine desired state. These double negative MS loves are a bit confusing
44+
$DesiredStateName = $Settings.state.value ?? $Settings.state
45+
$DesiredState = $DesiredStateName -eq 'disabled' ? $true : $false
46+
$StateIsCorrect = $CurrentConfig -eq $DesiredState
47+
48+
# Input validation
49+
if ([string]::IsNullOrWhiteSpace($DesiredStateName) -or $DesiredState -eq 'Select a value') {
50+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'EXODirectSend: Invalid state parameter set' -sev Error
51+
Return
52+
}
53+
54+
# Remediate if needed
55+
if ($Settings.remediate -eq $true) {
56+
57+
Write-Host 'Time to remediate'
58+
if ($StateIsCorrect -eq $true) {
59+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Direct Send is already set to $DesiredStateName." -sev Info
60+
} else {
61+
try {
62+
$null = New-ExoRequest -TenantID $Tenant -cmdlet 'Set-OrganizationConfig' -cmdParams @{ RejectDirectSend = $DesiredState }
63+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Direct Send has been set to $DesiredStateName." -sev Info
64+
$CurrentState = $DesiredState
65+
} catch {
66+
$ErrorMessage = Get-CippException -Exception $_
67+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to set Direct Send state: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
68+
}
69+
}
70+
}
71+
72+
# Alert if needed
73+
if ($Settings.alert -eq $true) {
74+
75+
if ($StateIsCorrect -eq $true) {
76+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Direct Send is set to $DesiredStateName as required." -sev Info
77+
} else {
78+
$CurrentStateName = $CurrentState ? 'disabled' : 'enabled'
79+
Write-StandardsAlert -message "Direct Send is $CurrentStateName but should be $DesiredStateName" -object $CurrentConfig -tenant $Tenant -standardName 'EXODirectSend' -standardId $Settings.standardId
80+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Direct Send is $CurrentStateName but should be $DesiredStateName." -sev Info
81+
}
82+
}
83+
84+
# Report if needed
85+
if ($Settings.report -eq $true) {
86+
87+
Set-CIPPStandardsCompareField -FieldName 'standards.EXODirectSend' -FieldValue $StateIsCorrect -Tenant $Tenant
88+
Add-CIPPBPAField -FieldName 'EXODirectSend' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
89+
}
90+
}

0 commit comments

Comments
 (0)