tak.Get-DKIMRecord.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Get-DKIMRecord {
    <#
    .SYNOPSIS
        Get DKIM Record for a domain.
    .DESCRIPTION
        This function uses Resolve-DNSName to get the DKIM Record for a given domain. Objects with a DomainName property,
        such as returned by Get-AcceptedDomain, can be piped to this function. The function defaults to "selector1" as this
        is typically used with Exchange Online.
    .EXAMPLE
        Get-AcceptedDomain | Get-DKIMRecord
 
        This example gets DKIM records for all domains returned by Get-AcceptedDomain.
    #>

    [CmdletBinding(HelpUri = 'https://ntsystems.it/PowerShell/TAK/Get-DKIMRecord/')]
    param (
        # Specify the Domain name to use in the query.
        [Parameter(Mandatory=$true,
            ValueFromPipelineByPropertyName=$true,
            ValueFromPipeline=$true)]
        [string]
        $DomainName,
        
        # Specify a selector name to use in the query.
        [Parameter()]
        [string[]]
        $Selector = "selector1",
        
        # Specify a DNS server to query.
        [Parameter()]
        [string] 
        $Server
    )
    process {
        foreach ($S in $Selector) {
            $params = @{
                Name = "$s._domainkey.$DomainName"
                ErrorAction = "SilentlyContinue"
            }
            if($Server) { $params.Add("Server",$Server) }
            $dnsTxt = Resolve-DnsName @params -Type TXT | Where-Object Type -eq TXT  
            $dnsTxt | Select-Object @{Name = "DKIM"; Expression = {"$DomainName`:$s"}},@{Name = "Record"; Expression = {$_.Strings}}    
        }
    }    
}