{"id":285,"date":"2020-07-15T17:08:01","date_gmt":"2020-07-15T16:08:01","guid":{"rendered":"http:\/\/brgeek.com.br\/wordpress\/?p=285"},"modified":"2020-07-15T17:08:03","modified_gmt":"2020-07-15T16:08:03","slug":"powershell-get-dns-forwarder-information","status":"publish","type":"post","link":"http:\/\/brgeek.com.br\/wordpress\/2020\/07\/15\/powershell-get-dns-forwarder-information\/","title":{"rendered":"Powershell &#8211; Get DNS Forwarder Information"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\" data-line=\"\">&lt;#\n.SYNOPSIS\n   Gets the DNS forwarder information, if any, from the specified Windows DNS server.\n\n.DESCRIPTION\n   Gets the DNS forwarder information, if any, from the specified Windows DNS server.\n\n.NOTES\n   Written by Michael Goulart\n\n.EXAMPLE\n   .\\Get-DnsForwarders -Computers contoso01,contoso02\n\n   DNSServer ZoneName             ZoneType DsIntegrated MasterServers\n   --------- --------             -------- ------------ -------------\n   contoso01 168.192.in-addr.arpa        1         True\n   contoso01 contoso.com                 1         True\n   contoso01 TrustAnchors                1         True\n   contoso01 google.com                  4        False 173.194.33.1,173.194.33.2\n   contoso02 168.192.in-addr.arpa        1         True\n   contoso02 contoso.com                 1         True\n\n.EXAMPLE\n   Type servers.txt | .\\Get-DnsForwarders -Credentials (Get-Credential contoso\\administrator)\n\n   (Where servers.txt contains contoso01 and contoso02. The user will be prompted for the password.)\n\n   DNSServer ZoneName             ZoneType DsIntegrated MasterServers\n   --------- --------             -------- ------------ -------------\n   contoso01 168.192.in-addr.arpa        1         True\n   contoso01 contoso.com                 1         True\n   contoso01 TrustAnchors                1         True\n   contoso01 google.com                  4        False 173.194.33.1,173.194.33.2\n   contoso02 168.192.in-addr.arpa        1         True\n   contoso02 contoso.com                 1         True\n\n.EXAMPLE\n   $Creds = Get-Credential contoso\\administrator\n   .\\Get-DnsForwarders -Computer contoso01 -Credentials $Creds\n\n   DNSServer ZoneName             ZoneType DsIntegrated MasterServers\n   --------- --------             -------- ------------ -------------\n   contoso01 168.192.in-addr.arpa        1         True\n   contoso01 contoso.com                 1         True\n   contoso01 TrustAnchors                1         True\n   contoso01 google.com                  4        False 173.194.33.1,173.194.33.2\n\n.PARAMETER Computers\n   The name(s) of the computer(s) running Microsoft DNS whose forwarder information is processed.\n   Alternatively, the computer name(s) can be piped to the script.\n\n.PARAMETER Credentials\n   The optional credentials to be used when connecting to the target computers with WMI.  If omitted,\n   the credentials of the current user are used.\n\n.INPUTS\n   The computer name(s) if not specified on the command line.\n\n.OUTPUTS\n   Filtered System.Management.ManagementObject objects with the DNS zone information\n\n#&gt;\n[CmdLetBinding()]\nParam(\n   [Parameter(\n      Mandatory=$True,\n      ValueFromPipeline=$True,\n      ValueFromPipelinebyPropertyName=$True\n      )\n   ]\n   [string[]] $Computers,\n   [Parameter(\n      Mandatory=$False\n      )\n   ]\n   [System.Management.Automation.PSCredential] $Credentials\n)\n\n# WMI namespace and class containing zone information\nBegin {\n   $NameSpace = &quot;root\\MicrosoftDNS&quot;\n   $Class = &quot;MicrosoftDNS_Zone&quot;\n}\n\n# For each computer specified, use WMI to get the information for all DNS zones it hosts.\nProcess {\n   ForEach ($Computer in $Computers) {\n\n      # If they specified credentials, use them, else use the current users credentials\n      If ($Credential) {\n         $Zones = Get-WMIObject -Computer $Computer -Namespace $NameSpace -Class $Class -Credential $Credentials\n      }\n      Else {\n         $Zones = Get-WMIObject -Computer $Computer -Namespace $NameSpace -Class $Class\n      }\n\n      # Process the zone information into nicely named and formatted objects\n      $Zones | Select -Property @{n=&#039;DNSServerName&#039;; e={$_.DnsServerName}},\n                                @{n=&#039;ZoneName&#039;;      e={$_.ContainerName}},\n                                @{n=&#039;ZoneType&#039;;      e={$_.ZoneType}},\n                                @{n=&#039;DsIntegrated&#039;;  e={$_.DsIntegrated}},\n                                @{n=&#039;MasterServers&#039;; e={([string]::Join(&#039;,&#039;, $_.MasterServers))}}\n   }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[68,8,67,6,69],"class_list":["post-285","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-dns","tag-michael-goulart","tag-microsoft-dns","tag-powershell","tag-powershell-code"],"jetpack_featured_media_url":"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2017\/09\/powershell-tips-and-tricks_w_640.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/comments?post=285"}],"version-history":[{"count":2,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":287,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/285\/revisions\/287"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media?parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/categories?post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/tags?post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}