How to use CreateZone in PowerShell to add DNS zones?

I'm trying to create a simple PowerShell script for a Windows Server 2008 Standard to add DNS entries. I am running the script on the local server running DNS. But I keep getting a "Generic failure" error on the CreateZone:

PS C:\Users\Administrator> $dnsserver=[wmiclass]"\\.\ROOT\Microsoftdns:Microsoftdns_zone"
PS C:\Users\Administrator> $dnsserver.createzone("mydomain.com.",0,$False,"mydomain.com.dns")
Exception calling "CreateZone" : "Generic failure "
At line:1 char:22
+ $dnsserver.CreateZone( <<<< "mydomain.com.",0,$False,"mydomain.com.dns")

I suspect the problem is with the definition of $dnsServer. Rather than using "\\.\" I have used the domain name "\\DC1\" as well as the fully qualified domain name (e.g., DC1.mybigdomain.local) but the same error occurs.  Any thoughts?

CreateZone Method Reference: http://msdn.microsoft.com/en-us/library/ms682760(VS.85).aspx


$dnsServer=[wmiclass]"\\.\ROOT\Microsoftdns:Microsoftdns_zone"
$dnsServer.CreateZone("mydomain.com.",0,$False,"mydomain.com.dns")

Open in new window

LVL 1
lesterw2Asked:
Who is Participating?
 
lesterw2Connect With a Mentor Author Commented:
I've tried it both with and without a period. Many examples I saw included the period (which is technically correct from what I understand). Thanks for the thought though.
0
 
OriNetworksConnect With a Mentor Commented:
Are you running the script as a user that has access to create in DNS?

Also are you aware that you have a period (.) after your domain? I havent used this command before but its worth a shot!
$dnsServer=[wmiclass]"\\.\ROOT\Microsoftdns:Microsoftdns_zone"
$dnsServer.CreateZone("mydomain.com.",0,$False,"mydomain.com.dns")
 
change to
 
$dnsServer=[wmiclass]"\\.\ROOT\Microsoftdns:Microsoftdns_zone"
$dnsServer.CreateZone("mydomain.com",0,$False,"mydomain.com.dns")

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.