Public/Email/Get-DKIMRecord.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Get-DKIMRecord {

    <#
    .SYNOPSIS
    Gets DKIM records for the requested domain(s).
 
    .DESCRIPTION
    Gets DKIM records for the requested domain(s).
     
    .PARAMETER Domain
     The domain(s) to get the DKIM records of.
     
    .EXAMPLE
    Get-DKIMRecord IntegrisIt.com,Microsoft.com
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [STRING[]]$Domain
    )

    $CommonDKIMSelectors = @(
        "selector1"
        "selector2"
        "selector3"
        "google"
        "k1"
        "k2"
        "k3"
        "key1"
        "key2"
        "key3"
        "jsqa"
        "litesrv" 
        "mxvault"
        "dkim"
        "s1" 
        "s2" 
        "s3"
        "pps"
        "pps2"
        "pps3"
        "ctct1" 
        "ctct2"
        "sm" 
        "sig1"
        "sig2"
        "zendesk1" 
        "zendesk2" 
    )

    $Results = @()

    $TotalCount = $Domain.Count
    $CurrentCount = 0

    FOREACH ($Entry in $Domain) { 

 
        Write-IntegrisProgressBar -TotalCount $TotalCount -CurrentCount $CurrentCount -Activity "Getting DKIM Records" -Status "Getting DKIM Records for [$Entry]" -ID 47918292 
        $CurrentCount++ 

        $DKIMKeys = @()
        FOREACH ($Selector in $CommonDKIMSelectors) {     
            $DKIMKeys += Resolve-DNSName -Type TXT -Name "$Selector._DomainKey.$Entry" -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*.$Entry*" -and $_.Type -eq "TXT" }
            Start-Sleep -Milliseconds 15
            $DKIMKeys += Resolve-DNSName -Type CNAME -Name "$Selector._DomainKey.$Entry" -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "*.$Entry*" -and $_.Type -eq "CNAME" }
            Start-Sleep -Milliseconds 15
        }

       

        FOREACH ($Item in $DKIMKeys) {

             IF ($Item.NameHost) { $Value = $Item.NameHost } ELSE { $Value = $Item.Strings }

            $Results += [PSCustomObject]@{
                PSTypeName = 'IntegrisPowerShell.DNSRecord'
                Domain = $Entry
                Name = $Item.Name
                Type = $Item.Type
                Purpose = "DKIM"            
                Value = $Value
                Preference = ""
            }
        }
    }

    Write-IntegrisLogFile $Results 

    RETURN $Results
}