Resolve-DnsName.psm1

function Resolve-DnsName {
    param(
        [string]$Name,
        [string]$Type = "A"
    )

    $typeSwitch = @{
        "A"     = "A"
        "AAAA"  = "AAAA"
        "MX"    = "MX"
        "TXT"   = "TXT"
        "NS"    = "NS"
        "CNAME" = "CNAME"
        "SRV"   = "SRV"
        "PTR"   = "PTR"
    }

    if (-not $typeSwitch.ContainsKey($Type)) {
        throw "Invalid DNS record type: $Type"
    }

    $result = & dig +short $Name $Type

    if ($result -eq "") {
        Write-Host "No records found for $Name of type $Type"
        return
    }

    $result -split "`n" | ForEach-Object {
        [PSCustomObject]@{
            HostName = $Name
            RecordType = $Type
            RecordData = $_
        }
    }
}