PSWinDocumentation.DNS.psm1

function Get-WinDNSInformation {
    param([string[]] $ComputerName,
        [string] $Splitter)
    if ($null -eq $TypesRequired) { }
    $DNSServers = @{ }
    foreach ($Computer in $ComputerName) { $Data = [ordered] @{ }
        $Data.ServerCache = Get-WinDnsServerCache -ComputerName $Computer
        $Data.ServerClientSubnets = Get-DnsServerClientSubnet -ComputerName $Computer
        $Data.ServerDiagnostics = Get-WinDnsServerDiagnostics -ComputerName $Computer
        $Data.ServerDirectoryPartition = Get-WinDnsServerDirectoryPartition -ComputerName $Computer -Splitter $Splitter
        $Data.ServerDsSetting = Get-WinDnsServerDsSetting -ComputerName $Computer
        $Data.ServerEdns = Get-WinDnsServerEDns -ComputerName $Computer
        $Data.ServerForwarder = Get-WinDnsServerForwarder -ComputerName $Computer
        $Data.ServerGlobalNameZone = Get-WinDnsServerGlobalNameZone -ComputerName $Computer
        $Data.ServerGlobalQueryBlockList = Get-WinDnsServerGlobalQueryBlockList -ComputerName $Computer -Splitter $Splitter
        $Data.ServerRecursion = Get-WinDnsServerRecursion -ComputerName $Computer
        $Data.ServerRecursionScopes = Get-WinDnsServerRecursionScope -ComputerName $Computer
        $Data.ServerResponseRateLimiting = Get-WinDnsServerResponseRateLimiting -ComputerName $Computer
        $Data.ServerResponseRateLimitingExceptionlists = Get-DnsServerResponseRateLimitingExceptionlist -ComputerName $Computer
        $Data.ServerRootHint = Get-WinDnsRootHint -ComputerName $Computer
        $Data.ServerScavenging = Get-WinDnsServerScavenging -ComputerName $Computer
        $Data.ServerSetting = Get-WinDnsServerSettings -ComputerName $Computer
        $Data.VirtualizedServer = $DNSServer.VirtualizedServer
        $Data.VirtualizationInstance = Get-WinDnsServerVirtualizationInstance -ComputerName $Computer
        $DNSServers.$Computer = $Data
    }
    return $DNSServers
}
function Get-WinDnsRootHint {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $ServerRootHints = Get-DnsServerRootHint -ComputerName $ComputerName
    foreach ($_ in $ServerRootHints.IPAddress) {
        [PSCustomObject] @{DistinguishedName = $_.DistinguishedName
            HostName = $_.HostName
            RecordClass = $_.RecordClass
            IPv4Address = $_.RecordData.IPv4Address.IPAddressToString
            IPv6Address = $_.RecordData.IPv6Address.IPAddressToString
            RecordType = $_.RecordType
            Timestamp = $_.Timestamp
            TimeToLive = $_.TimeToLive
            Type = $_.Type
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerCache {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerCache = Get-DnsServerCache -ComputerName $ComputerName
    foreach ($_ in $DnsServerCache) {
        [PSCustomObject] @{DistinguishedName = $_.DistinguishedName
            IsAutoCreated = $_.IsAutoCreated
            IsDsIntegrated = $_.IsDsIntegrated
            IsPaused = $_.IsPaused
            IsReadOnly = $_.IsReadOnly
            IsReverseLookupZone = $_.IsReverseLookupZone
            IsShutdown = $_.IsShutdown
            ZoneName = $_.ZoneName
            ZoneType = $_.ZoneType
            EnablePollutionProtection = $_.EnablePollutionProtection
            IgnorePolicies = $_.IgnorePolicies
            LockingPercent = $_.LockingPercent
            MaxKBSize = $_.MaxKBSize
            MaxNegativeTtl = $_.MaxNegativeTtl
            MaxTtl = $_.MaxTtl
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerDiagnostics {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerDiagnostics = Get-DnsServerDiagnostics -ComputerName $ComputerName
    foreach ($_ in $DnsServerDiagnostics) {
        [PSCustomObject] @{FilterIPAddressList = $_.FilterIPAddressList
            Answers = $_.Answers
            EnableLogFileRollover = $_.EnableLogFileRollover
            EnableLoggingForLocalLookupEvent = $_.EnableLoggingForLocalLookupEvent
            EnableLoggingForPluginDllEvent = $_.EnableLoggingForPluginDllEvent
            EnableLoggingForRecursiveLookupEvent = $_.EnableLoggingForRecursiveLookupEvent
            EnableLoggingForRemoteServerEvent = $_.EnableLoggingForRemoteServerEvent
            EnableLoggingForServerStartStopEvent = $_.EnableLoggingForServerStartStopEvent
            EnableLoggingForTombstoneEvent = $_.EnableLoggingForTombstoneEvent
            EnableLoggingForZoneDataWriteEvent = $_.EnableLoggingForZoneDataWriteEvent
            EnableLoggingForZoneLoadingEvent = $_.EnableLoggingForZoneLoadingEvent
            EnableLoggingToFile = $_.EnableLoggingToFile
            EventLogLevel = $_.EventLogLevel
            FullPackets = $_.FullPackets
            LogFilePath = $_.LogFilePath
            MaxMBFileSize = $_.MaxMBFileSize
            Notifications = $_.Notifications
            Queries = $_.Queries
            QuestionTransactions = $_.QuestionTransactions
            ReceivePackets = $_.ReceivePackets
            SaveLogsToPersistentStorage = $_.SaveLogsToPersistentStorage
            SendPackets = $_.SendPackets
            TcpPackets = $_.TcpPackets
            UdpPackets = $_.UdpPackets
            UnmatchedResponse = $_.UnmatchedResponse
            Update = $_.Update
            UseSystemEventLog = $_.UseSystemEventLog
            WriteThrough = $_.WriteThrough
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerDirectoryPartition {
    [CmdLetBinding()]
    param([string] $ComputerName,
        [string] $Splitter)
    $DnsServerDirectoryPartition = Get-DnsServerDirectoryPartition -ComputerName $ComputerName
    foreach ($_ in $DnsServerDirectoryPartition) {
        [PSCustomObject] @{DirectoryPartitionName = $_.DirectoryPartitionName
            CrossReferenceDistinguishedName = $_.CrossReferenceDistinguishedName
            DirectoryPartitionDistinguishedName = $_.DirectoryPartitionDistinguishedName
            Flags = $_.Flags
            Replica = if ($Splitter -ne '') { $_.Replica -join $Splitter } else { $_.Replica }
            State = $_.State
            ZoneCount = $_.ZoneCount
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerDsSetting {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerDsSetting = Get-DnsServerDsSetting -ComputerName $ComputerName
    foreach ($_ in $DnsServerDsSetting) {
        [PSCustomObject] @{DirectoryPartitionAutoEnlistInterval = $_.DirectoryPartitionAutoEnlistInterval
            LazyUpdateInterval = $_.LazyUpdateInterval
            MinimumBackgroundLoadThreads = $_.MinimumBackgroundLoadThreads
            RemoteReplicationDelay = $_.RemoteReplicationDelay
            TombstoneInterval = $_.TombstoneInterval
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerEDns {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerDsSetting = Get-DnsServerEDns -ComputerName $ComputerName
    foreach ($_ in $DnsServerDsSetting) {
        [PSCustomObject] @{CacheTimeout = $_.CacheTimeout
            EnableProbes = $_.EnableProbes
            EnableReception = $_.EnableReception
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerForwarder {
    [CmdLetBinding()]
    param([string[]] $ComputerName,
        [switch] $Formatted,
        [string] $Splitter = ', ')
    foreach ($Computer in $ComputerName) {
        $DnsServerForwarder = Get-DnsServerForwarder -ComputerName $Computer
        foreach ($_ in $DnsServerForwarder) {
            if ($Formatted) {
                [PSCustomObject] @{IPAddress = $_.IPAddress
                    ReorderedIPAddress = $_.ReorderedIPAddress
                    EnableReordering = $_.EnableReordering
                    Timeout = $_.Timeout
                    UseRootHint = $_.UseRootHint
                    GatheredFrom = $Computer
                }
            } else {
                [PSCustomObject] @{IPAddress = $_.IPAddress -join $Splitter
                    ReorderedIPAddress = $_.ReorderedIPAddress -join $Splitter
                    EnableReordering = $_.EnableReordering
                    Timeout = $_.Timeout
                    UseRootHint = $_.UseRootHint
                    GatheredFrom = $Computer
                }
            }
        }
    }
}
function Get-WinDnsServerGlobalNameZone {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerGlobalNameZone = Get-DnsServerGlobalNameZone -ComputerName $ComputerName
    foreach ($_ in $DnsServerGlobalNameZone) {
        [PSCustomObject] @{AlwaysQueryServer = $_.AlwaysQueryServer
            BlockUpdates = $_.BlockUpdates
            Enable = $_.Enable
            EnableEDnsProbes = $_.EnableEDnsProbes
            GlobalOverLocal = $_.GlobalOverLocal
            PreferAaaa = $_.PreferAaaa
            SendTimeout = $_.SendTimeout
            ServerQueryInterval = $_.ServerQueryInterval
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerGlobalQueryBlockList {
    [CmdLetBinding()]
    param([string] $ComputerName,
        [string] $Splitter)
    $ServerGlobalQueryBlockList = Get-DnsServerGlobalQueryBlockList -ComputerName $ComputerName
    foreach ($_ in $ServerGlobalQueryBlockList) {
        [PSCustomObject] @{Enable = $_.Enable
            List = if ($Splitter -ne '') { $_.List -join $Splitter } else { $_.List }
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerRecursion {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerRecursion = Get-DnsServerRecursion -ComputerName $Computer
    foreach ($_ in $DnsServerRecursion) {
        [PSCustomObject] @{AdditionalTimeout = $_.AdditionalTimeout
            Enable = $_.Enable
            RetryInterval = $_.RetryInterval
            SecureResponse = $_.SecureResponse
            Timeout = $_.Timeout
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerRecursionScope {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerRecursionScope = Get-DnsServerRecursionScope -ComputerName $ComputerName
    foreach ($_ in $DnsServerRecursionScope) {
        [PSCustomObject] @{Name = $_.Name
            Forwarder = $_.Forwarder
            EnableRecursion = $_.EnableRecursion
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerResponseRateLimiting {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerResponseRateLimiting = Get-DnsServerResponseRateLimiting -ComputerName $ComputerName
    foreach ($_ in $DnsServerResponseRateLimiting) {
        [PSCustomObject] @{ResponsesPerSec = $_.ResponsesPerSec
            ErrorsPerSec = $_.ErrorsPerSec
            WindowInSec = $_.WindowInSec
            IPv4PrefixLength = $_.IPv4PrefixLength
            IPv6PrefixLength = $_.IPv6PrefixLength
            LeakRate = $_.LeakRate
            TruncateRate = $_.TruncateRate
            MaximumResponsesPerWindow = $_.MaximumResponsesPerWindow
            Mode = $_.Mode
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerScavenging {
    [CmdLetBinding()]
    param([string[]] $ComputerName,
        [string] $Domain)
    if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName }
    foreach ($Computer in $ComputerName) {
        try { $DnsServerScavenging = Get-DnsServerScavenging -ComputerName $Computer -ErrorAction Stop } catch {
            [PSCustomObject] @{NoRefreshInterval = $null
                RefreshInterval = $null
                ScavengingInterval = $null
                ScavengingState = $null
                LastScavengeTime = $null
                GatheredFrom = $Computer
            }
            continue
        }
        foreach ($_ in $DnsServerScavenging) {
            [PSCustomObject] @{NoRefreshInterval = $_.NoRefreshInterval
                RefreshInterval = $_.RefreshInterval
                ScavengingInterval = $_.ScavengingInterval
                ScavengingState = $_.ScavengingState
                LastScavengeTime = $_.LastScavengeTime
                GatheredFrom = $Computer
            }
        }
    }
}
function Get-WinDnsServerSettings {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerSetting = Get-DnsServerSetting -ComputerName $ComputerName -All
    foreach ($_ in $DnsServerSetting) {
        [PSCustomObject] @{AllIPAddress = $_.AllIPAddress
            ListeningIPAddress = $_.ListeningIPAddress
            BuildNumber = $_.BuildNumber
            ComputerName = $_.ComputerName
            EnableDnsSec = $_.EnableDnsSec
            EnableIPv6 = $_.EnableIPv6
            IsReadOnlyDC = $_.IsReadOnlyDC
            MajorVersion = $_.MajorVersion
            MinorVersion = $_.MinorVersion
            GatheredFrom = $ComputerName
        }
    }
}
function Get-WinDnsServerVirtualizationInstance {
    [CmdLetBinding()]
    param([string] $ComputerName)
    $DnsServerVirtualizationInstance = Get-DnsServerVirtualizationInstance -ComputerName $ComputerName
    foreach ($_ in $DnsServerVirtualizationInstance) {
        [PSCustomObject] @{VirtualizationInstance = $_.VirtualizationInstance
            FriendlyName = $_.FriendlyName
            Description = $_.Description
            GatheredFrom = $ComputerName
        }
    }
}
Export-ModuleMember -Function @('Get-WinDNSInformation') -Alias @()