-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5600 from salbeck-sit/EXOSmtpDaneInbound
EXOSmtpDaneInbound - initial release
- Loading branch information
Showing
10 changed files
with
697 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
343 changes: 343 additions & 0 deletions
343
Modules/Microsoft365DSC/DSCResources/MSFT_EXOSmtpDaneInbound/MSFT_EXOSmtpDaneInbound.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,343 @@ | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DomainName, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present', 'Absent')] | ||
[System.String] | ||
$Ensure, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$Credential, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$ApplicationSecret | ||
) | ||
|
||
New-M365DSCConnection -Workload 'ExchangeOnline' ` | ||
-InboundParameters $PSBoundParameters | Out-Null | ||
|
||
#Ensure the proper dependencies are installed in the current environment. | ||
Confirm-M365DSCDependencies | ||
|
||
#region Telemetry | ||
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '') | ||
$CommandName = $MyInvocation.MyCommand | ||
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` | ||
-CommandName $CommandName ` | ||
-Parameters $PSBoundParameters | ||
Add-M365DSCTelemetryEvent -Data $data | ||
#endregion | ||
|
||
$nullResult = $PSBoundParameters | ||
$nullResult.Ensure = 'Absent' | ||
try | ||
{ | ||
$instance = Get-AcceptedDomain -Identity $DomainName -ErrorAction SilentlyContinue | ||
if ($null -eq $instance -or $instance.SmtpDaneStatus -ne 'Enabled') | ||
{ | ||
return $nullResult | ||
} | ||
|
||
Write-Verbose -Message "Found an instance with DomainName {$DomainName}" | ||
$results = @{ | ||
DomainName = $instance.DomainName | ||
Ensure = 'Present' | ||
Credential = $Credential | ||
ApplicationId = $ApplicationId | ||
TenantId = $TenantId | ||
CertificateThumbprint = $CertificateThumbprint | ||
ApplicationSecret = $ApplicationSecret | ||
} | ||
return [System.Collections.Hashtable] $results | ||
} | ||
catch | ||
{ | ||
New-M365DSCLogEntry -Message 'Error retrieving data:' ` | ||
-Exception $_ ` | ||
-Source $($MyInvocation.MyCommand.Source) ` | ||
-TenantId $TenantId ` | ||
-Credential $Credential | ||
|
||
return $nullResult | ||
} | ||
} | ||
|
||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DomainName, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present', 'Absent')] | ||
[System.String] | ||
$Ensure, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$Credential, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$ApplicationSecret | ||
) | ||
|
||
New-M365DSCConnection -Workload 'ExchangeOnline' ` | ||
-InboundParameters $PSBoundParameters | Out-Null | ||
|
||
#Ensure the proper dependencies are installed in the current environment. | ||
Confirm-M365DSCDependencies | ||
|
||
#region Telemetry | ||
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '') | ||
$CommandName = $MyInvocation.MyCommand | ||
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` | ||
-CommandName $CommandName ` | ||
-Parameters $PSBoundParameters | ||
Add-M365DSCTelemetryEvent -Data $data | ||
#endregion | ||
|
||
$currentInstance = Get-TargetResource @PSBoundParameters | ||
|
||
if ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Absent') | ||
{ | ||
Write-Verbose -Message "Enabling SmtpDaneInbound for {$DomainName}" | ||
try { | ||
Enable-SmtpDaneInbound -DomainName $DomainName -ErrorAction Stop | Out-Null | ||
} | ||
catch { | ||
write-verbose "Cannot enable SmtpDaneInbound for DomainName $DomainName - check that DNSSEC is enabled" | ||
New-M365DSCLogEntry -Message "Error enabling SmtpDaneInbound for DomainName '$DomainName'" ` | ||
-Exception $_ ` | ||
-Source $($MyInvocation.MyCommand.Source) ` | ||
-TenantId $TenantId ` | ||
-Credential $Credential | ||
} | ||
} | ||
elseif ($Ensure -eq 'Absent' -and $currentInstance.Ensure -eq 'Present') | ||
{ | ||
Write-Verbose -Message "Disabling SmtpDaneInbound for {$DomainName}" | ||
Disable-SmtpDaneInbound -DomainName $currentInstance.DomainName | ||
} | ||
} | ||
|
||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$DomainName, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present', 'Absent')] | ||
[System.String] | ||
$Ensure, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$Credential, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$ApplicationSecret | ||
) | ||
|
||
#Ensure the proper dependencies are installed in the current environment. | ||
Confirm-M365DSCDependencies | ||
|
||
#region Telemetry | ||
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '') | ||
$CommandName = $MyInvocation.MyCommand | ||
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` | ||
-CommandName $CommandName ` | ||
-Parameters $PSBoundParameters | ||
Add-M365DSCTelemetryEvent -Data $data | ||
#endregion | ||
|
||
Write-Verbose -Message "Testing configuration of {$DomainName}" | ||
|
||
$CurrentValues = Get-TargetResource @PSBoundParameters | ||
|
||
if ($CurrentValues.Ensure -ne $Ensure) | ||
{ | ||
Write-Verbose -Message "Test-TargetResource returned $false" | ||
return $false | ||
} | ||
|
||
Write-Verbose -Message "Current Values: DomainName=$($currentValue.DomainName), Ensure=$($currentValues.Ensure)" | ||
Write-Verbose -Message "Target Values: DomainName=$DomainName, Ensure=$Ensure" | ||
|
||
$testResult = $true | ||
|
||
Write-Verbose -Message "Test-TargetResource returned $testResult" | ||
|
||
return $testResult | ||
} | ||
|
||
function Export-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.String])] | ||
param | ||
( | ||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$Credential, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$ApplicationId, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$TenantId, | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$ApplicationSecret, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$CertificateThumbprint, | ||
|
||
[Parameter()] | ||
[Switch] | ||
$ManagedIdentity | ||
) | ||
|
||
$ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' ` | ||
-InboundParameters $PSBoundParameters | ||
|
||
#Ensure the proper dependencies are installed in the current environment. | ||
Confirm-M365DSCDependencies | ||
|
||
#region Telemetry | ||
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '') | ||
$CommandName = $MyInvocation.MyCommand | ||
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName ` | ||
-CommandName $CommandName ` | ||
-Parameters $PSBoundParameters | ||
Add-M365DSCTelemetryEvent -Data $data | ||
#endregion | ||
|
||
try | ||
{ | ||
[array]$getValue = Get-AcceptedDomain -ResultSize Unlimited -ErrorAction Stop | ||
|
||
$i = 1 | ||
$dscContent = '' | ||
if ($getValue.Length -eq 0) | ||
{ | ||
Write-Host $Global:M365DSCEmojiGreenCheckMark | ||
} | ||
else | ||
{ | ||
Write-Host "`r`n" -NoNewline | ||
} | ||
foreach ($config in $getValue) | ||
{ | ||
if ($null -ne $Global:M365DSCExportResourceInstancesCount) | ||
{ | ||
$Global:M365DSCExportResourceInstancesCount++ | ||
} | ||
|
||
$displayedKey = $config.DomainName | ||
if (-not [String]::IsNullOrEmpty($config.displayName)) | ||
{ | ||
$displayedKey = $config.displayName | ||
} | ||
Write-Host " |---[$i/$($getValue.Count)] $displayedKey" -NoNewline | ||
$params = @{ | ||
DomainName = $config.DomainName | ||
Ensure = 'Present' | ||
Credential = $Credential | ||
ApplicationId = $ApplicationId | ||
TenantId = $TenantId | ||
CertificateThumbprint = $CertificateThumbprint | ||
ApplicationSecret = $ApplicationSecret | ||
|
||
} | ||
|
||
$Results = Get-TargetResource @Params | ||
$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode ` | ||
-Results $Results | ||
|
||
$currentDSCBlock = Get-M365DSCExportContentForResource -ResourceName $ResourceName ` | ||
-ConnectionMode $ConnectionMode ` | ||
-ModulePath $PSScriptRoot ` | ||
-Results $Results ` | ||
-Credential $Credential | ||
$dscContent += $currentDSCBlock | ||
Save-M365DSCPartialExport -Content $currentDSCBlock ` | ||
-FileName $Global:PartialExportFileName | ||
$i++ | ||
Write-Host $Global:M365DSCEmojiGreenCheckMark | ||
} | ||
return $dscContent | ||
} | ||
catch | ||
{ | ||
Write-Host $Global:M365DSCEmojiRedX | ||
|
||
New-M365DSCLogEntry -Message 'Error during Export:' ` | ||
-Exception $_ ` | ||
-Source $($MyInvocation.MyCommand.Source) ` | ||
-TenantId $TenantId ` | ||
-Credential $Credential | ||
|
||
return '' | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
14 changes: 14 additions & 0 deletions
14
...s/Microsoft365DSC/DSCResources/MSFT_EXOSmtpDaneInbound/MSFT_EXOSmtpDaneInbound.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("EXOSmtpDaneInbound")] | ||
class MSFT_EXOSmtpDaneInbound : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the accepted domain in the Exchange Online organization where you want to enable SMTP DANE")] String DomainName; | ||
[Write, Description("Present ensures SmtpDaneInbound is enabled, absent ensures it is disabled."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; | ||
[Write, Description("Credentials of the Exchange Global Admin"), EmbeddedInstance("MSFT_Credential")] string Credential; | ||
[Write, Description("Id of the Azure Active Directory application to authenticate with.")] String ApplicationId; | ||
[Write, Description("Id of the Azure Active Directory tenant used for authentication.")] String TenantId; | ||
[Write, Description("Thumbprint of the Azure Active Directory application's authentication certificate to use for authentication.")] String CertificateThumbprint; | ||
[Write, Description("Username can be made up to anything but password will be used for CertificatePassword"), EmbeddedInstance("MSFT_Credential")] String CertificatePassword; | ||
[Write, Description("Path to certificate used in service principal usually a PFX file.")] String CertificatePath; | ||
[Write, Description("Managed ID being used for authentication.")] Boolean ManagedIdentity; | ||
[Write, Description("Access token used for authentication.")] String AccessTokens[]; | ||
}; |
9 changes: 9 additions & 0 deletions
9
Modules/Microsoft365DSC/DSCResources/MSFT_EXOSmtpDaneInbound/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
# EXOSmtpDaneInbound | ||
|
||
## Description: | ||
|
||
This resource configures SmtpDaneInbound for an accepted domain in Exchange Online. | ||
Reference: https://learn.microsoft.com/en-us/powershell/module/exchange/enable-smtpdaneinbound?view=exchange-ps | ||
|
||
Note that enabling DANE requires that the accepted domain is configured for DNSSEC and the public MX-record updated correspondingly |
Oops, something went wrong.