Simple DNS Zone Creation Script

This entry was posted by on Friday, 22 April, 2011 at

This is a really simple DNS Zone Creation script, but since I don’t have a space limitation (ha, 5KB really matters) I thought I would put it here.

The Problem:

I needed an automated way to create primary zones in one of my 3 forests while creating conditional forward domains in my other 2 forests.

      do

          {

                  $location = Read-Host “`n[1] = domain1.local`n[2] = domain2.local`n[3] = domain3.local`n`nChoose Zone Location”

                  if ($location -eq “”){Write-Host “`n`nYou must choose one”}

                  if ($location -eq “1”){$location = “domain1.local”}

                  if ($location -eq “2”){$location = “domain2.local”}

                  if ($location -eq “3”){$location = “domain3.local”}

          }

      while ($location -eq “”)

     

      do

          {

                  $zoneName = Read-Host “Enter Zone Name (exact naming, e.g., domain1.local)”

          }

      while ($zoneName -eq “”)

     

function CreateZone{

      param([string]$location,[string]$zoneName)

            if ($location -eq “domain1.local”){

                  Write-Host “`nCreating Primary DS Zone in $location”

                  C:\windows\sysnative\dnscmd.exe $location /ZoneAdd $zoneName /DsPrimary /file $zoneName

                  C:\windows\sysnative\dnscmd.exe domain2.local /ZoneAdd $zoneName /DsForwarder 10.10.10.203 10.10.10.204 10.55.55.11 10.55.55.12

                  C:\windows\sysnative\dnscmd.exe domain3.local /ZoneAdd $zoneName /DsForwarder 10.10.10.203 10.10.10.204 10.55.55.11 10.55.55.12

                  }

 

            if ($location -eq “domain2.local”){

                  Write-Host “`nCreating Primary DS Zone in $location”

                  C:\windows\sysnative\dnscmd.exe $location /ZoneAdd $zoneName /DsPrimary /file $zoneName

                  C:\windows\sysnative\dnscmd.exe domain1.local /ZoneAdd $zoneName /DsForwarder 172.16.7.20 172.16.7.21

                  C:\windows\sysnative\dnscmd.exe domain3.local /ZoneAdd $zoneName /DsForwarder 172.16.7.20 172.16.7.21

                  }

 

            if ($location -eq “domain3.local”){

                  Write-Host “`nCreating Primary DS Zone in $location”

                  C:\windows\sysnative\dnscmd.exe $location /ZoneAdd $zoneName /DsPrimary /file $zoneName

                  C:\windows\sysnative\dnscmd.exe domain1.local /ZoneAdd $zoneName /DsForwarder 172.16.8.11 172.16.8.12

                  C:\windows\sysnative\dnscmd.exe domain2.local /ZoneAdd $zoneName /DsForwarder 172.16.8.11 172.16.8.12

            }

}

 

CreateZone -location $location -zoneName $zoneName

 

Setup:

The only item that needs to be in place is that dnscmd.exe be installed. This is installed when you install the Windows 2003 Server Support Tools.

You can download the script by clicking here.

Script Steps:

1.       Ask user for zone location.

2.       Ask user for zone name.

3.       Create primary zone in zone location and conditional forward zones in other two domains

Hopefully you find this useful.

~Lane


Leave a Reply