Solved

DNS management using powershell

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running a 2nd company from the same location 3 38
Domain Controller FSMO 7 35
Powershell command 2 22
Windows DNS Server Caching 3 27
Resolve DNS query failed errors for Exchange
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

10 Experts available now in Live!

Get 1:1 Help Now