[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1095
  • Last Modified:

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


Open in new window

2 Solutions
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!
change to

Open in new window

lesterw2Author 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.

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now