Solved

DNS management using powershell

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

Office 365 Training for Admins

Learn how to provision tenants, synchronize on-premise Active Directory, and implement Single Sign-On with these master level course.  Only from Platform Scholar

Question has a verified solution.

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

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
Learn about cloud computing and its benefits for small business owners.

739 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