Solved

DNS management using powershell

Posted on 2008-10-29
4
1,393 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
Comment Utility

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
Comment Utility

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
Comment Utility
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
Comment Utility
Thanks for the help, it is possible but rather hard to do it at first.

Cheers.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I've written instructions for one router type, but this principle may be useful for others of the same brand and even other brands of router. Problem: I had an issue especially with mobile devices that refused to use DNS information supplied via…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

11 Experts available now in Live!

Get 1:1 Help Now