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, [string] $Domain = $ENV:USERDNSDOMAIN) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $ServerRootHints = Get-DnsServerRootHint -ComputerName $Computer 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 = $Computer } } } } function Get-WinDnsServerCache { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $DnsServerCache = Get-DnsServerCache -ComputerName $Computer 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 = $Computer } } } } 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, [string] $Domain = $ENV:USERDNSDOMAIN, [switch] $Formatted, [string] $Splitter = ', ') if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { try { $DnsServerForwarder = Get-DnsServerForwarder -ComputerName $Computer -ErrorAction Stop } catch { $ErrorMessage = $_.Exception.Message -replace "`n", " " -replace "`r", " " Write-Warning "Get-WinDnsServerForwarder - Error $ErrorMessage" continue } foreach ($_ in $DnsServerForwarder) { if ($Formatted) { [PSCustomObject] @{IPAddress = $_.IPAddress.IPAddressToString -join $Splitter ReorderedIPAddress = $_.ReorderedIPAddress.IPAddressToString -join $Splitter EnableReordering = $_.EnableReordering Timeout = $_.Timeout UseRootHint = $_.UseRootHint GatheredFrom = $Computer } } else { [PSCustomObject] @{IPAddress = $_.IPAddress.IPAddressToString ReorderedIPAddress = $_.ReorderedIPAddress.IPAddressToString EnableReordering = $_.EnableReordering Timeout = $_.Timeout UseRootHint = $_.UseRootHint GatheredFrom = $Computer } } } } } function Get-WinDnsServerGlobalNameZone { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $DnsServerGlobalNameZone = Get-DnsServerGlobalNameZone -ComputerName $Computer foreach ($_ in $DnsServerGlobalNameZone) { [PSCustomObject] @{AlwaysQueryServer = $_.AlwaysQueryServer BlockUpdates = $_.BlockUpdates Enable = $_.Enable EnableEDnsProbes = $_.EnableEDnsProbes GlobalOverLocal = $_.GlobalOverLocal PreferAaaa = $_.PreferAaaa SendTimeout = $_.SendTimeout ServerQueryInterval = $_.ServerQueryInterval GatheredFrom = $Computer } } } } function Get-WinDnsServerGlobalQueryBlockList { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN, [switch] $Formatted, [string] $Splitter = ', ') if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $ServerGlobalQueryBlockList = Get-DnsServerGlobalQueryBlockList -ComputerName $Computer foreach ($_ in $ServerGlobalQueryBlockList) { if ($Formatted) { [PSCustomObject] @{Enable = $_.Enable List = $_.List -join $Splitter GatheredFrom = $Computer } } else { [PSCustomObject] @{Enable = $_.Enable List = $_.List GatheredFrom = $Computer } } } } } function Get-WinDnsServerRecursion { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $DnsServerRecursion = Get-DnsServerRecursion -ComputerName $Computer foreach ($_ in $DnsServerRecursion) { [PSCustomObject] @{AdditionalTimeout = $_.AdditionalTimeout Enable = $_.Enable RetryInterval = $_.RetryInterval SecureResponse = $_.SecureResponse Timeout = $_.Timeout GatheredFrom = $Computer } } } } function Get-WinDnsServerRecursionScope { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $DnsServerRecursionScope = Get-DnsServerRecursionScope -ComputerName $Computer foreach ($_ in $DnsServerRecursionScope) { [PSCustomObject] @{Name = $_.Name Forwarder = $_.Forwarder EnableRecursion = $_.EnableRecursion GatheredFrom = $Computer } } } } function Get-WinDnsServerResponseRateLimiting { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } foreach ($Computer in $ComputerName) { $DnsServerResponseRateLimiting = Get-DnsServerResponseRateLimiting -ComputerName $Computer foreach ($_ in $DnsServerResponseRateLimiting) { [PSCustomObject] @{ResponsesPerSec = $_.ResponsesPerSec ErrorsPerSec = $_.ErrorsPerSec WindowInSec = $_.WindowInSec IPv4PrefixLength = $_.IPv4PrefixLength IPv6PrefixLength = $_.IPv6PrefixLength LeakRate = $_.LeakRate TruncateRate = $_.TruncateRate MaximumResponsesPerWindow = $_.MaximumResponsesPerWindow Mode = $_.Mode GatheredFrom = $Computer } } } } function Get-WinDnsServerScavenging { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN) 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 } } } function Get-WinDnsServerZones { [CmdLetBinding()] param([string[]] $ComputerName, [string] $Domain = $ENV:USERDNSDOMAIN, [switch] $ReverseLookupZone, [switch] $PrimaryZone, [string] $ZoneName) if ($Domain -and -not $ComputerName) { $ComputerName = (Get-ADDomainController -Filter * -Server $Domain).HostName } $ReadyZones = foreach ($Computer in $ComputerName) { if ($ZoneName) { $Zones = Get-DnsServerZone -ComputerName $Computer -Name $ZoneName } else { $Zones = Get-DnsServerZone -ComputerName $Computer } foreach ($_ in $Zones) { if ($_.ZoneType -eq 'Primary') { $ZoneAging = Get-DnsServerZoneAging -Name $_.ZoneName -ComputerName $Computer $AgingEnabled = $ZoneAging.AgingEnabled $AvailForScavengeTime = $ZoneAging.AvailForScavengeTime $RefreshInterval = $ZoneAging.RefreshInterval $NoRefreshInterval = $ZoneAging.NoRefreshInterval $ScavengeServers = $ZoneAging.ScavengeServers } else { $AgingEnabled = $null $AvailForScavengeTime = $null $RefreshInterval = $null $NoRefreshInterval = $null $ScavengeServers = $null } [PSCustomObject] @{'ZoneName' = $_.'ZoneName' 'AgingEnabled' = $AgingEnabled 'AvailForScavengeTime' = $AvailForScavengeTime 'RefreshInterval' = $RefreshInterval 'NoRefreshInterval' = $NoRefreshInterval 'ScavengeServers' = $ScavengeServers 'NotifyServers' = $_.'NotifyServers' 'SecondaryServers' = $_.'SecondaryServers' 'AllowedDcForNsRecordsAutoCreation' = $_.'AllowedDcForNsRecordsAutoCreation' 'DistinguishedName' = $_.'DistinguishedName' 'IsAutoCreated' = $_.'IsAutoCreated' 'IsDsIntegrated' = $_.'IsDsIntegrated' 'IsPaused' = $_.'IsPaused' 'IsReadOnly' = $_.'IsReadOnly' 'IsReverseLookupZone' = $_.'IsReverseLookupZone' 'IsShutdown' = $_.'IsShutdown' 'ZoneType' = $_.'ZoneType' 'DirectoryPartitionName' = $_.'DirectoryPartitionName' 'DynamicUpdate' = $_.'DynamicUpdate' 'IgnorePolicies' = $_.'IgnorePolicies' 'IsSigned' = $_.'IsSigned' 'IsWinsEnabled' = $_.'IsWinsEnabled' 'Notify' = $_.'Notify' 'ReplicationScope' = $_.'ReplicationScope' 'SecureSecondaries' = $_.'SecureSecondaries' 'ZoneFile' = $_.'ZoneFile' 'GatheredFrom' = $Computer } } } $Output = @(if ($ReverseLookupZone -and $PrimaryZone) { $ReadyZones | Where-Object { $_.IsReverseLookupZone -eq $true -and $_.ZoneType -eq 'Primary' } } elseif ($ReverseLookupZone) { $ReadyZones | Where-Object { $_.IsReverseLookupZone -eq $true } } elseif ($PrimaryZone) { $ReadyZones | Where-Object { $_.ZoneType -eq 'Primary' -and $_.IsReverseLookupZone -eq $false } } else { $ReadyZones }) $Output } Export-ModuleMember -Function @('Get-WinDNSInformation') -Alias @() |