Script Center > Gallery > Networking > DNS Zone Information CSV collector
TechNet Script Center logo

Welcome to the TechNet Script Center Gallery!

Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.

DNS Zone Information CSV collector

(Community)
  • Average Rating (0)
  • Created by Nathan Linley
  • Published on 11/10/2009
Rate it:
 
 
 
 
 
Script Code
Perl
#dns zone enumeration and detail gathering

#run the command with arguments of the dns servers hosting the zones.  This script enumerates
#all zones, collects some of the extended details and outputs to CSV format.  Requires dnscmd.exe and 
#appropriate rights on the remote machine

foreach (@ARGV) {
	my $filename = $_ . ".csv";
	open OUTFILE, ">$filename" ||die "Can't open output file\n";

	print OUTFILE "Zone Name,Type,Storage,Updates,DS Integrated,Aging On,Refresh Aging,No Refresh Aging,Scavenge Available\n";
	my $dnsserver = $_;
	$output = `dnscmd $dnsserver /enumzones`;
	@outputarr = split(/\n/,$output);
	$beginning = 0;
	foreach (@outputarr) {
		
		if (!($beginning)) {
			
			if ($_ =~ /Zone name/) {
				$beginning = 1;
			}
		} else {
			chomp($_);
			$_ =~ s/^\s//;
			my @temparr = split(/\s+/,$_);
			if ($temparr[0] =~ /\./) {
				#proper zone found,
				#Format:  Name, Type, Storage, Properties(multiple)
				#   properties  Secure Rev Aging
				my $details = getdetail($dnsserver,$temparr[0]);
				my $outline = "$temparr[0],$temparr[1],$temparr[2],$details";

				print OUTFILE $outline;
			}	
			
		}
				
		
	} #end of all output from enumzones
	close OUTFILE;
} #end foreach server's passed as args

sub getdetail {
	my ($dnsserver,$zone) = @_;
	
	my $zoneinfo = `dnscmd $dnsserver /zoneinfo $zone`;
	
	my @zonedetails = split(/\n/,$zoneinfo);
	my ($zoneupdate, $dsintegrated, $aging, $agerefresh, $age_no_refresh, $scavenge_avail) = "";
	foreach (@zonedetails) {
		my $line = $_;
		if ($line =~ /update/) {
			$zoneupdate = parsevalue($line);
		} elsif ($line =~ /aging/) {
			$aging = parsevalue($line);
		} elsif ($line =~ /DS integrated/) {
			$dsintegrated = parsevalue($line);
		} elsif ($line =~ /refresh interval/) {
			$agerefresh = parsevalue($line);
		} elsif ($line =~ /no refresh/) {
			$age_no_refresh = parsevalue($line);
		} elsif ($line =~ /scavenge available/) {
			$scavenge_avail = parsevalue($line);
		}
	} #end details
	my $retval = "$zoneupdate,$dsintegrated,$aging,$agerefresh,$age_no_refresh,$scavenge_avail\n";
	
	return $retval;
}

sub parsevalue {
	my $val = @_[0];
	my @temparr = split(/=/, $val);
	$val = $temparr[1];
	$val =~ s/ //g;
	chomp $val;
	return $val;	
}
Platforms
Windows Server 2008 R2 No
Windows Server 2008 No
Windows Server 2003 Yes
Windows 7 No
Windows Vista No
Windows XP No
Windows 2000 No
For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.