DSCResources/cEXOTransportRule/cEXOTransportRule.schema.psm1

configuration cEXOTransportRule {
    param (
        [Parameter()]
        [hashtable[]]
        $Items
)

<#
EXOTransportRule [String] #ResourceName
{
    Name = [string]
    [AccessTokens = [string[]]]
    [ActivationDate = [string]]
    [ADComparisonAttribute = [string]]
    [ADComparisonOperator = [string]{ Equal | NotEqual }]
    [AddManagerAsRecipientType = [string]{ Bcc | Cc | Redirect | To }]
    [AddToRecipients = [string[]]]
    [AnyOfCcHeader = [string[]]]
    [AnyOfCcHeaderMemberOf = [string[]]]
    [AnyOfRecipientAddressContainsWords = [string[]]]
    [AnyOfRecipientAddressMatchesPatterns = [string[]]]
    [AnyOfToCcHeader = [string[]]]
    [AnyOfToCcHeaderMemberOf = [string[]]]
    [AnyOfToHeader = [string[]]]
    [AnyOfToHeaderMemberOf = [string[]]]
    [ApplicationId = [string]]
    [ApplyClassification = [string]]
    [ApplyHtmlDisclaimerFallbackAction = [string]{ Ignore | Reject | Wrap }]
    [ApplyHtmlDisclaimerLocation = [string]{ Append | Prepend }]
    [ApplyHtmlDisclaimerText = [string]]
    [ApplyOME = [bool]]
    [ApplyRightsProtectionCustomizationTemplate = [string]]
    [ApplyRightsProtectionTemplate = [string]]
    [AttachmentContainsWords = [string[]]]
    [AttachmentExtensionMatchesWords = [string[]]]
    [AttachmentHasExecutableContent = [bool]]
    [AttachmentIsPasswordProtected = [bool]]
    [AttachmentIsUnsupported = [bool]]
    [AttachmentMatchesPatterns = [string[]]]
    [AttachmentNameMatchesPatterns = [string[]]]
    [AttachmentProcessingLimitExceeded = [bool]]
    [AttachmentPropertyContainsWords = [string[]]]
    [AttachmentSizeOver = [string]]
    [BetweenMemberOf1 = [string[]]]
    [BetweenMemberOf2 = [string[]]]
    [BlindCopyTo = [string[]]]
    [CertificatePassword = [PSCredential]]
    [CertificatePath = [string]]
    [CertificateThumbprint = [string]]
    [Comments = [string]]
    [ContentCharacterSetContainsWords = [string[]]]
    [CopyTo = [string[]]]
    [Credential = [PSCredential]]
    [DeleteMessage = [bool]]
    [DependsOn = [string[]]]
    [DlpPolicy = [string]]
    [Enabled = [bool]]
    [Ensure = [string]{ Absent | Present }]
    [ExceptIfADComparisonAttribute = [string]]
    [ExceptIfADComparisonOperator = [string]{ Equal | NotEqual }]
    [ExceptIfAnyOfCcHeader = [string[]]]
    [ExceptIfAnyOfCcHeaderMemberOf = [string[]]]
    [ExceptIfAnyOfRecipientAddressContainsWords = [string[]]]
    [ExceptIfAnyOfRecipientAddressMatchesPatterns = [string[]]]
    [ExceptIfAnyOfToCcHeader = [string[]]]
    [ExceptIfAnyOfToCcHeaderMemberOf = [string[]]]
    [ExceptIfAnyOfToHeader = [string[]]]
    [ExceptIfAnyOfToHeaderMemberOf = [string[]]]
    [ExceptIfAttachmentContainsWords = [string[]]]
    [ExceptIfAttachmentExtensionMatchesWords = [string[]]]
    [ExceptIfAttachmentHasExecutableContent = [bool]]
    [ExceptIfAttachmentIsPasswordProtected = [bool]]
    [ExceptIfAttachmentIsUnsupported = [bool]]
    [ExceptIfAttachmentMatchesPatterns = [string[]]]
    [ExceptIfAttachmentNameMatchesPatterns = [string[]]]
    [ExceptIfAttachmentProcessingLimitExceeded = [bool]]
    [ExceptIfAttachmentPropertyContainsWords = [string[]]]
    [ExceptIfAttachmentSizeOver = [string]]
    [ExceptIfBetweenMemberOf1 = [string[]]]
    [ExceptIfBetweenMemberOf2 = [string[]]]
    [ExceptIfContentCharacterSetContainsWords = [string[]]]
    [ExceptIfFrom = [string[]]]
    [ExceptIfFromAddressContainsWords = [string[]]]
    [ExceptIfFromAddressMatchesPatterns = [string[]]]
    [ExceptIfFromMemberOf = [string[]]]
    [ExceptIfFromScope = [string]{ InOrganization | NotInOrganization }]
    [ExceptIfHasClassification = [string]]
    [ExceptIfHasNoClassification = [bool]]
    [ExceptIfHasSenderOverride = [bool]]
    [ExceptIfHeaderContainsMessageHeader = [string]]
    [ExceptIfHeaderContainsWords = [string[]]]
    [ExceptIfHeaderMatchesMessageHeader = [string]]
    [ExceptIfHeaderMatchesPatterns = [string[]]]
    [ExceptIfManagerAddresses = [string[]]]
    [ExceptIfManagerForEvaluatedUser = [string]]
    [ExceptIfMessageContainsDataClassifications = [string[]]]
    [ExceptIfMessageSizeOver = [string]]
    [ExceptIfMessageTypeMatches = [string]{ ApprovalRequest | AutoForward | Calendaring | Encrypted | OOF | PermissionControlled | ReadReceipt | Signed | Voicemail }]
    [ExceptIfRecipientADAttributeContainsWords = [string[]]]
    [ExceptIfRecipientADAttributeMatchesPatterns = [string[]]]
    [ExceptIfRecipientAddressContainsWords = [string[]]]
    [ExceptIfRecipientAddressMatchesPatterns = [string[]]]
    [ExceptIfRecipientDomainIs = [string[]]]
    [ExceptIfRecipientInSenderList = [string[]]]
    [ExceptIfSCLOver = [string]]
    [ExceptIfSenderADAttributeContainsWords = [string[]]]
    [ExceptIfSenderADAttributeMatchesPatterns = [string[]]]
    [ExceptIfSenderDomainIs = [string[]]]
    [ExceptIfSenderInRecipientList = [string[]]]
    [ExceptIfSenderIpRanges = [string[]]]
    [ExceptIfSenderManagementRelationship = [string]{ DirectReport | Manager }]
    [ExceptIfSentTo = [string[]]]
    [ExceptIfSentToMemberOf = [string[]]]
    [ExceptIfSentToScope = [string]{ ExternalNonPartner | ExternalPartner | InOrganization | NotInOrganization }]
    [ExceptIfSubjectContainsWords = [string[]]]
    [ExceptIfSubjectMatchesPatterns = [string[]]]
    [ExceptIfSubjectOrBodyContainsWords = [string[]]]
    [ExceptIfSubjectOrBodyMatchesPatterns = [string[]]]
    [ExceptIfWithImportance = [string]{ High | Low | Normal }]
    [ExpiryDate = [string]]
    [From = [string[]]]
    [FromAddressContainsWords = [string[]]]
    [FromAddressMatchesPatterns = [string[]]]
    [FromMemberOf = [string[]]]
    [FromScope = [string]{ InOrganization | NotInOrganization }]
    [GenerateIncidentReport = [string]]
    [GenerateNotification = [string]]
    [HasClassification = [string]]
    [HasNoClassification = [bool]]
    [HasSenderOverride = [bool]]
    [HeaderContainsMessageHeader = [string]]
    [HeaderContainsWords = [string[]]]
    [HeaderMatchesMessageHeader = [string]]
    [HeaderMatchesPatterns = [string[]]]
    [IncidentReportContent = [string[]]]
    [ManagedIdentity = [bool]]
    [ManagerAddresses = [string[]]]
    [ManagerForEvaluatedUser = [string]{ Recipient | Sender }]
    [MessageContainsDataClassifications = [string[]]]
    [MessageSizeOver = [string]]
    [MessageTypeMatches = [string]{ ApprovalRequest | AutoForward | Calendaring | Encrypted | OOF | PermissionControlled | ReadReceipt | Signed | Voicemail }]
    [Mode = [string]{ Audit | AuditAndNotify | Enforce }]
    [ModerateMessageByManager = [bool]]
    [ModerateMessageByUser = [string[]]]
    [NotifySender = [string]{ NotifyOnly | RejectMessage | RejectUnlessExplicitOverride | RejectUnlessFalsePositiveOverride | RejectUnlessSilentOverride }]
    [PrependSubject = [string]]
    [Priority = [UInt32]]
    [PsDscRunAsCredential = [PSCredential]]
    [Quarantine = [bool]]
    [RecipientADAttributeContainsWords = [string[]]]
    [RecipientADAttributeMatchesPatterns = [string[]]]
    [RecipientAddressContainsWords = [string[]]]
    [RecipientAddressMatchesPatterns = [string[]]]
    [RecipientAddressType = [string]{ Original | Resolved }]
    [RecipientDomainIs = [string[]]]
    [RecipientInSenderList = [string[]]]
    [RedirectMessageTo = [string[]]]
    [RejectMessageEnhancedStatusCode = [string]]
    [RejectMessageReasonText = [string]]
    [RemoveHeader = [string]]
    [RemoveOME = [bool]]
    [RemoveOMEv2 = [bool]]
    [RemoveRMSAttachmentEncryption = [bool]]
    [RouteMessageOutboundConnector = [string]]
    [RouteMessageOutboundRequireTls = [bool]]
    [RuleErrorAction = [string]{ Defer | Ignore }]
    [RuleSubType = [string]{ Dlp | None }]
    [SCLOver = [string]]
    [SenderADAttributeContainsWords = [string[]]]
    [SenderADAttributeMatchesPatterns = [string[]]]
    [SenderAddressLocation = [string]{ Envelope | Header | HeaderOrEnvelope }]
    [SenderDomainIs = [string[]]]
    [SenderInRecipientList = [string]]
    [SenderIpRanges = [string[]]]
    [SenderManagementRelationship = [string]{ DirectReport | Manager }]
    [SentTo = [string[]]]
    [SentToMemberOf = [string[]]]
    [SentToScope = [string]{ ExternalNonPartner | ExternalPartner | InOrganization | NotInOrganization }]
    [SetAuditSeverity = [string]{ DoNotAudit | High | Low | Medium }]
    [SetHeaderName = [string]]
    [SetHeaderValue = [string]]
    [SetSCL = [string]]
    [StopRuleProcessing = [bool]]
    [SubjectContainsWords = [string[]]]
    [SubjectMatchesPatterns = [string[]]]
    [SubjectOrBodyContainsWords = [string[]]]
    [SubjectOrBodyMatchesPatterns = [string[]]]
    [TenantId = [string]]
    [WithImportance = [string]{ High | Low | Normal }]
}
 
#>



    Import-DscResource -ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName Microsoft365DSC

    $dscResourceName = 'EXOTransportRule'

    $param = $PSBoundParameters
    $param.Remove("InstanceName")

    $dscParameterKeys = 'Name' -split ', '

        foreach ($item in $Items)
        {
            if (-not $item.ContainsKey('Ensure'))
            {
                $item.Ensure = 'Present'
            }
            $keyValues = foreach ($key in $dscParameterKeys)
        {
            $item.$key
        }
        $executionName = $keyValues -join '_'
        $executionName = $executionName -replace "[\s()\\:*-+/{}```"']", '_'
        (Get-DscSplattedResource -ResourceName $dscResourceName -ExecutionName $executionName -Properties $item -NoInvoke).Invoke($item)
    }
}