locked
Get DNS Zones on Multiple Servers with a txt file RRS feed

  • Question

  • I am trying to Get Dns zone on multiple server with a txt file but i did not get a computer name in the output

    $DNSServer = Gc C:\dnsservers.txt
    $Zones = @(Get-DnsServerZone -ComputerName $DNSServer)
    ForEach ($Zone in $Zones) | | Select-Object zoneName,ZoneType,MasterServers | export-csv -Path C:\Dnsresult.csv

    what a need is column Computername , zonename ,Zonetype and Master server for All the servers in the txt file any help is appreciated .


    Wednesday, June 20, 2018 7:38 PM

All replies

  • I am trying to Get Dns zone on multiple server with a txt file but i did not get a computer name in the output

    $DNSServer = Gc C:\dnsservers.txt
    $Zones = @(Get-DnsServerZone -ComputerName $DNSServer)
    ForEach ($Zone in $Zones) | | Select-Object zoneName,ZoneType,MasterServers | export-csv -Path C:\Dnsresult.csv

    what a need is column Computername , zonename ,Zonetype and Master server for All the servers in the txt file any help is appreciated .


    $DNSServer = Gc C:\dnsservers.txt
    
    $DNSServer | ForEach {
      $ComputerName = $_
      $Zones = @(Get-DnsServerZone -ComputerName $_)
      ForEach ($Zone in $Zones) | $dnszone = @{
        ComputerName = $ComputerName
        ZoneName = $_.ZoneName
        ZoneType = $_.ZoneType
        MasterServers = $_.MasterServers} | export-csv -Path C:\Dnsresult.csv
      }
    }
    How about something like that? I haven't tried the code, but the concept should be correct.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Wednesday, June 20, 2018 9:40 PM
  • A DNSServerZone instance does not have a "MasterServers" property.  IF you use WMI to get this class it will include the computer name of the queried server.

    "MaterServers" would be an array and cannot be exported directly but must be converted to a string.


    \_(ツ)_/

    Wednesday, June 20, 2018 10:07 PM
  • Get-WmiObject MicrosoftDNS_Zone -ns root\MicrosoftDNS  -Computer $dnsserver|
          select PsComputerName, Name,Zonetype, @{n='MasterServers';e={$_.MasterServers -join '|'}}
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682757%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

    \_(ツ)_/


    • Edited by jrv Wednesday, June 20, 2018 10:15 PM
    Wednesday, June 20, 2018 10:14 PM
  • Thanks it's work on 2012r2 and error 2008R2 .
    Thursday, June 21, 2018 2:26 PM