Solved

need assistance with a DNS zone update script

Posted on 2014-10-23
7
176 Views
Last Modified: 2014-10-23
hello, can someone provide a script that we can use to update a remote DNS zone with records.

here is the scenario, we have a team in one region that adds machines to the domain, we have another stub zone server in a different region that we have to update with the new systems added [due to a NAT requirement]

we need a script that they can run that will prompt to enter the name & IP address, and from there update the DNS zone on a remove standalone DNS server.

many thanks!

S.
0
Comment
Question by:siber1
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40400993
You can probably just pipe the values into dnscmd

dnscmd [<ServerName>] /recordadd <ZoneName> <NodeName> <RRType> <RRData>

Do a  Read-host for the values you need to populate.

$val1 = Read-host "Please Enter the hostname"
$val2 = Read-Host "Please enter the ip address"
#Then run the dns cmd
#I am guessing server name will be hardcoded as probably the record type
dnscmd DNSSERVER1 /recordadd domain.local $val1.domain.local. A $val2

Open in new window

0
 

Author Comment

by:siber1
ID: 40401017
hello becraig, when I run the script I get this confirmation:
Add A Record for . at mydomain.com
Command completed successfully.

Open in new window


no record is added to the zone, it looks like perhaps the variables are not being passed correctly?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40401021
ok let us do a write-host for the command for debugging so we can be sure:
$val1 = Read-host "Please Enter the hostname"
$val2 = Read-Host "Please enter the ip address"
#Then run the dns cmd
#I am guessing server name will be hardcoded as probably the record type

write-host "dnscmd DNSSERVER1 /recordadd domain.local $val1.domain.local. A $val2"

dnscmd DNSSERVER1 /recordadd domain.local $val1.domain.local. A $val2

Open in new window

0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:siber1
ID: 40401029
interesting, the write-host looks perfect, but it doesn't create the record with the variables.

If I run the line that "write host" provides manually in powershell it creates the record fine

here is what write host displays;
dnscmd impmadc1 /recordadd mydomain.com ztest.mydomain.com. A 10.100.2.30

Open in new window


when I run the script, no record is created, when I run it manually the record creates as expected. thoughts?
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40401052
Let's try this and see:


$val1 = Read-host "Please Enter the hostname"
$val2 = Read-Host "Please enter the ip address"

$cmdval = "dnscmd DNSSERVER1 /recordadd domain.local $val1.domain.local. A $val2"
Invoke-Expression $cmdval  

Open in new window

0
 

Author Closing Comment

by:siber1
ID: 40401054
brilliant. works perfectly. thx much!
0
 
LVL 29

Expert Comment

by:becraig
ID: 40401055
Np glad to help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
A procedure for exporting installed hotfix details of remote computers using powershell
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question