This powershell script is useful if you need to extract DNS forwarder information from any specified Windows Server or also from a list of servers.
<#
.SYNOPSIS
Gets the DNS forwarder information, if any, from the specified Windows DNS server.
.DESCRIPTION
Gets the DNS forwarder information, if any, from the specified Windows DNS server.
.NOTES
Written by Michael Goulart
.EXAMPLE
.\Get-DnsForwarders -Computers contoso01,contoso02
DNSServer ZoneName ZoneType DsIntegrated MasterServers
--------- -------- -------- ------------ -------------
contoso01 168.192.in-addr.arpa 1 True
contoso01 contoso.com 1 True
contoso01 TrustAnchors 1 True
contoso01 google.com 4 False 173.194.33.1,173.194.33.2
contoso02 168.192.in-addr.arpa 1 True
contoso02 contoso.com 1 True
.EXAMPLE
Type servers.txt | .\Get-DnsForwarders -Credentials (Get-Credential contoso\administrator)
(Where servers.txt contains contoso01 and contoso02. The user will be prompted for the password.)
DNSServer ZoneName ZoneType DsIntegrated MasterServers
--------- -------- -------- ------------ -------------
contoso01 168.192.in-addr.arpa 1 True
contoso01 contoso.com 1 True
contoso01 TrustAnchors 1 True
contoso01 google.com 4 False 173.194.33.1,173.194.33.2
contoso02 168.192.in-addr.arpa 1 True
contoso02 contoso.com 1 True
.EXAMPLE
$Creds = Get-Credential contoso\administrator
.\Get-DnsForwarders -Computer contoso01 -Credentials $Creds
DNSServer ZoneName ZoneType DsIntegrated MasterServers
--------- -------- -------- ------------ -------------
contoso01 168.192.in-addr.arpa 1 True
contoso01 contoso.com 1 True
contoso01 TrustAnchors 1 True
contoso01 google.com 4 False 173.194.33.1,173.194.33.2
.PARAMETER Computers
The name(s) of the computer(s) running Microsoft DNS whose forwarder information is processed.
Alternatively, the computer name(s) can be piped to the script.
.PARAMETER Credentials
The optional credentials to be used when connecting to the target computers with WMI. If omitted,
the credentials of the current user are used.
.INPUTS
The computer name(s) if not specified on the command line.
.OUTPUTS
Filtered System.Management.ManagementObject objects with the DNS zone information
#>
[CmdLetBinding()]
Param(
[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelinebyPropertyName=$True
)
]
[string[]] $Computers,
[Parameter(
Mandatory=$False
)
]
[System.Management.Automation.PSCredential] $Credentials
)
# WMI namespace and class containing zone information
Begin {
$NameSpace = "root\MicrosoftDNS"
$Class = "MicrosoftDNS_Zone"
}
# For each computer specified, use WMI to get the information for all DNS zones it hosts.
Process {
ForEach ($Computer in $Computers) {
# If they specified credentials, use them, else use the current users credentials
If ($Credential) {
$Zones = Get-WMIObject -Computer $Computer -Namespace $NameSpace -Class $Class -Credential $Credentials
}
Else {
$Zones = Get-WMIObject -Computer $Computer -Namespace $NameSpace -Class $Class
}
# Process the zone information into nicely named and formatted objects
$Zones | Select -Property @{n='DNSServerName'; e={$_.DnsServerName}},
@{n='ZoneName'; e={$_.ContainerName}},
@{n='ZoneType'; e={$_.ZoneType}},
@{n='DsIntegrated'; e={$_.DsIntegrated}},
@{n='MasterServers'; e={([string]::Join(',', $_.MasterServers))}}
}
}
0 Comments