Solved

DNS management using powershell

Posted on 2008-10-29
4
1,403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 71

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 71

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Occasionally you run into the website or two that will not resolve properly using your own DNS servers.  Some people simply set up global forwarders for their DNS server.  I don’t recommend doing this because it can cause problems resolving addresse…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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