Listing05_Create_Configure_Zone_DnsCmd (Perl)

This code can be found in Chapter 8 of Managing Enterprise Active Directory Services

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4

use strict;
use DnsCmd;

my $new_zone = 'xyz2.com';

# Create new dnscmd object and specify primary server
my $dnscmd = DnsCmd->new('dc1.xyz.com');

# Delete old A record
$dnscmd->ZoneAdd($new_zone,   # New zone name
                 '/DsPrimary'); # Zone Type
if ($dnscmd->error) {
   die "Error creating zone: ",$dnscmd->output;
}
else {
   print "Successfully created zone: ",$dnscmd->output;
}

# Disallow zone transfers
$dnscmd->Config($new_zone,'/SecureSecondarys' => 3);
die $dnscmd->output if $dnscmd->error;

# Only allow secure updates
$dnscmd->Config($new_zone,'/AllowUpdate' => 2);
die $dnscmd->output if $dnscmd->error;

# Turn on aging
$dnscmd->Config($new_zone,'/Aging' => 1);
die $dnscmd->output if $dnscmd->error;

# Scavenge at 14 days
$dnscmd->Config($new_zone,'/RefreshInterval' => 366);
die $dnscmd->output if $dnscmd->error;

$dnscmd->Config($new_zone,'/NoRefreshInterval' => 366);
die $dnscmd->output if $dnscmd->error;

print "Successfully configured zone\n";

This code has been viewed 785 times.

New from the creators of TechTasks.com: StatSheet.com