powershell script to modify DNS CNAME ALIAS


i have a csv file in this form:


i need a script to modify all the alias cname entry in my dns with new fqdn.
all alias is already exist, i need just to modify the fqdn.

thanks for help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What version of Windows Server is the DNS server running?

Server 2012 introduced :
Add-DnsServerResourceRecordA and Set-DnsServerResourceRecord
details here : http://technet.microsoft.com/en-us/library/jj649847.aspx

But if this is for Windows 2003 or 2008, DNSCMD would be the way to do this, the record would need to be deleted and added back in, the syntax is here:

cawasakiAuthor Commented:

my dns is windows 2008 r2.

are you sure for the record would need to be deleted and added back in??

Ideally when you use /recordadd it should overwrite/update the record.. Command format is something like..

dnscmd <dns server> /recordadd <zone> <alias> CNAME <Server fqdn>

Ref : http://technet.microsoft.com/en-us/library/cc783826(v=ws.10).aspx

For example..
#Following command will create a CNAME record ServerD and point it to MYDC.Domain.com

dnscmd ServerA /recordadd Domain.com ServerD CNAME MYDC.Domain.com

#and following code will update the record and point it to MYDC1.Domain.com

dnscmd ServerA /recordadd Domain.com ServerD CNAME MYDC1.Domain.com

Open in new window

So for bulk update, you may try the following code.. It will update the record if there is a matching alias name else it will create a new record.
Import-Csv c:\input.csv | % {dnscmd ServerA /recordadd Domain.com $_.alias cname $_.fqdn }

Open in new window

Input file format..

Open in new window

Or you can use DnsShell



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

cawasakiAuthor Commented:

i have test and have this error:

Command failed:  RPC_S_SERVER_UNAVAILABLE     1722    0x6BA

one question, when i look my dns console, all my alias (Cname) entry have the fqdn target host with a dot at the end.

for exemple:

dns config
do you now what are this dot and how i can keep it for the new entry?

Ideally fqdn in dns must end with a dot, which indicates it’s the complete name. Even if you didn’t add the dot at the end of FQDN, while resolving DNS will automatically append it for you.

If you do a nslookup for google.com. and google.com it will give you same result..

You may search in Google for more detailed explanation.. :-)

Regardig the error.. Are you running the command from server?
Check http://support.microsoft.com/kb/2027440
cawasakiAuthor Commented:
ok for the dot i have seen it have update and add the dot :)

not i lunsh the script from my admin server, its possible to specifiy on the script the dns server?
its possible to specifiy on the script the dns server?
It's already specified in code. You need to replace ServerA with your DNS server where you want to update the record.. Is that what you asking for?
cawasakiAuthor Commented:
ah yes i have not change serverA!
now it good it work :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.