Solved

DNS management using powershell

Posted on 2008-10-29
4
1,394 Views
Last Modified: 2012-05-05
Dear Experts,

i'm just wondering, is it possible to manipulate or managing DNS records using PowerShell ?

I've got incomplete Reverse DNS lookup zone which needs to be repopulated throughout the domain.
It's be great if there's any solution for that.

Thanks.
0
Comment
Question by:jjoz
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Chris Dent
ID: 22832439

You can use WMI to manage and create records; PowerShell can hook into WMI so yes, you can use PowerShell to manage DNS.

It's not quite as accessible as I'd like, but it does work.

For instance, modifying a record can be done like this:

$Record = Get-WMIObject -Class "MicrosoftDNS_AType" `
  -Namespace "root\MicrosoftDNS" -Computer dc01.internal.highorbit.co.uk `
  -Filter "ContainerName='thezone.net' AND OwnerName='test.thezone.net'"
$NewRecord = $Record.Modify($Record.TTL, "2.3.4.5")

Replace the Computer name and the values in the Filter. It's not entirely bug free; If you attempt to replace a record with the same data the record will be deleted.

There's also a CreateInstanceFromTextRepresentation Method of each class, that's documented here:

http://msdn.microsoft.com/en-us/library/ms682714(VS.85).aspx

That can also be called on the $Record above, but it should also be possible to execute that without first performing a query (although we'll still have to create an instance of the class).

HTH

Chris
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 22832717

Ahh here we go, it can also be done using the ManagementClass in .NET. That means converting this into PowerShell:

http://msdn.microsoft.com/en-us/library/ms143592.aspx

Not too hard though this is the important section (in PS) :)

$Scope = New-Object System.Management.ManagementScope("\\.\root\MicrosoftDNS")
$Path = New-Object System.Management.ManagementPath("MicrosoftDNS_AType")
$Options = New-Object System.Management.ObjectGetOptions($Null, [System.TimeSpan]::MaxValue, $True)
$Class = New-Object System.Management.ManagementClass($Scope, $Path, $Options)

Then we can call the slightly different CreateInstanceFromPropertyData defined here:

http://msdn.microsoft.com/en-us/library/ms682154(VS.85).aspx

To actually create a record. You should see that as an available Method if you run "$Class | Get-Member".

It's entirely possible there are much shorter ways to do it than this, but it's a reasonable beginning :)

Chris
0
 
LVL 1

Author Comment

by:jjoz
ID: 22836498
Wow,
you're amazing Chris !

I'll try that using PowerGUI and see how it goes then.

Cheers.
0
 
LVL 1

Author Closing Comment

by:jjoz
ID: 31511153
Thanks for the help, it is possible but rather hard to do it at first.

Cheers.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DNS on-premise and on-cloud 15 119
Office365 login in Page not accessible. 3 41
MX Backup 4 59
Fortigate 100D NTP Issue 4 52
Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found listed in my profile here: http:…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now