[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 767
  • Last Modified:

Add DNS records zones to an existing zone.


I have a dns primary zone  Test.com in domain1 that has about 50 records there is another dns zone from anothe domain (domain2), the dns zone has also the same name TEST.com and it has about 80 records.

I would like to add the records from the TEST.com zone in domain2 to the TEST.com zone in domain1

I looked at the DNSCMD command and didn't see a switch that can do that.

Any help?

Thanks
0
jskfan
Asked:
jskfan
  • 17
  • 13
1 Solution
 
Chris DentPowerShell DeveloperCommented:

Heh no, there wouldn't be a switch to do that. You'd have to script it because it's way outside normal DNS functionality.

If the zones are supposed to be the same, why isn't one of them Secondary?

Chris
0
 
jskfanAuthor Commented:
is it possible if they have different names ?
0
 
Chris DentPowerShell DeveloperCommented:

It's not "test.com" in both cases? DNS isn't case sensitive if that's the only difference.

Chris
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jskfanAuthor Commented:
I mean if you have record in a zone named AA.com and you want to add those records to a zone name BB.com without overwriting the existing records
0
 
Chris DentPowerShell DeveloperCommented:

Then we definitely need some scripting, nothing else will do it.

Do you care which language it's in? If you don't I'll probably make it PowerShell :)

Chris
0
 
jskfanAuthor Commented:
that's english.
0
 
Chris DentPowerShell DeveloperCommented:

Okay, well I'll get on with that first thing in the morning unless something blows up here :)

Chris
0
 
Chris DentPowerShell DeveloperCommented:

A bit later than I intended, but this does it (in PowerShell). The downside is that it has to run from the destination server since I haven't figured out how to pass authentication along with a WMI Class yet.

The other disadvantage is that you need access to WMI on both servers. It'll prompt for the password for the source server (twice).

Chris

$SrcServer = "sourceserver"
$SrcCredential = "domain\user"
$SrcZone = "testsrc.com"
 
$DstServer = "destinationserver"
$DstZone = "testdst.com"
 
$Classes = @("MicrosoftDNS_AType", "MicrosoftDNS_CNAMEType")
 
$NewRRClass = [WMIClass]"\\$DstServer\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
 
ForEach ($Class in $Classes) {
 
  $SrcRecords = Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
    -Computer $SrcServer -Filter "ContainerName='$SrcZone'" `
    -Credential $SrcCredential | Select-Object TextRepresentation
 
  $DstRecords = Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
    -Computer $DstServer -Filter "ContainerName='$DstZone'" `
   | Select-Object TextRepresentation
 
  ForEach ($Record in $SrcRecords) {
    $DstTextRepresentation = ($Record.TextRepresentation).Replace($SrcZone, $DstZone)
 
    If (!($DstRecords | ?{ $_.TextRepresentation -eq $DstTextRepresentation })) {
      $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( `
        $DstServer, $DstZone, $DstTextRepresentation)
    }
  }
}

Open in new window

0
 
jskfanAuthor Commented:


I pasted your code to a notepad and created myscript.vbs file.
I am getting this error:

Script C:\document and settings\administrator.mydomainname\desktop\myscript.vbs
line:1
char:1
Error:Invalid Charachter
code:800A0408
Source:Microsoft VBScript compilation error
0
 
Chris DentPowerShell DeveloperCommented:

PowerShell rather than VbScript, you'll need this to be able to run it :)

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

It'll paste into the command prompt.

I can rewrite it in VbScript if you want, it's just PowerShell is more fun / less code ;)

Chris
0
 
Chris DentPowerShell DeveloperCommented:

> It'll paste into the command prompt.

Er this isn't a very clear statement. I mean you can paste it into the PowerShell prompt, it'll (hopefully) become clear if you install it :)

Chris
0
 
jskfanAuthor Commented:
That's what I get when I run it

Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.

PS C:\Documents and Settings\administrator.mycompany> $SrcServer = "myDNSserver.mycompany.com"
PS C:\Documents and Settings\administrator.mycompany> $SrcCredential = "mydomain\myuseraccount"
PS C:\Documents and Settings\administrator.mycompany> $SrcZone = "mycompanyemailservices.net"
PS C:\Documents and Settings\administrator.mycompany>
PS C:\Documents and Settings\administrator.mycompany> $DstServer = "myDNSserver"
PS C:\Documents and Settings\administrator.mycompany> $DstZone = "mycompany.com"
PS C:\Documents and Settings\administrator.mycompany>
PS C:\Documents and Settings\administrator.mycompany> $Classes = @("MicrosoftDNS_AType", "MicrosoftDNS_CNAMEType")
PS C:\Documents and Settings\administrator.mycompany>
PS C:\Documents and Settings\administrator.mycompany> $NewRRClass = [WMIClass]"\\$DstServer\root\MicrosoftDNS:Microsoft
ResourceRecord"
PS C:\Documents and Settings\administrator.mycompany>
PS C:\Documents and Settings\administrator.mycompany> ForEach ($Class in $Classes) {
>>
>>   $SrcRecords = Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
>>     -Computer $SrcServer -Filter "ContainerName='$SrcZone'" `
>>     -Credential $SrcCredential | Select-Object TextRepresentation
>>
>>   $DstRecords = Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
>>     -Computer $DstServer -Filter "ContainerName='$DstZone'" `
>>    | Select-Object TextRepresentation
>>
>>   ForEach ($Record in $SrcRecords) {
>>     $DstTextRepresentation = ($Record.TextRepresentation).Replace($SrcZone, $DstZone)
>>
>>     If (!($DstRecords | ?{ $_.TextRepresentation -eq $DstTextRepresentation })) {
>>       $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( `
>>         $DstServer, $DstZone, $DstTextRepresentation)
>>     }
>>   }
>> }
>>
Get-WmiObject : User credentials cannot be used for local connections
At line:2 char:30
+   $SrcRecords = Get-WMIObject  <<<< -Namespace "root\MicrosoftDNS" -Class $Class `
You cannot call a method on a null-valued expression.
At line:9 char:66
+     $DstTextRepresentation = ($Record.TextRepresentation).Replace( <<<< $SrcZone, $DstZone)
Exception calling "CreateInstanceFromTextRepresentation" : "Invalid parameter "
At line:11 char:64
+       $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( <<<<  `
Get-WmiObject : User credentials cannot be used for local connections
At line:2 char:30
+   $SrcRecords = Get-WMIObject  <<<< -Namespace "root\MicrosoftDNS" -Class $Class `
You cannot call a method on a null-valued expression.
At line:9 char:66
+     $DstTextRepresentation = ($Record.TextRepresentation).Replace( <<<< $SrcZone, $DstZone)
Exception calling "CreateInstanceFromTextRepresentation" : "Invalid parameter "
At line:11 char:64
+       $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( <<<<  `
PS C:\Documents and Settings\administrator.mycompany>
0
 
Chris DentPowerShell DeveloperCommented:

Where are you running it from? It's only configured to run from the Destination Server at the moment. I'll see if I can fix the reason for that.

Chris
0
 
jskfanAuthor Commented:
all the zones are in one DNS server. I just want to add records from one zone to another without overwriting the records in the zone.
0
 
Chris DentPowerShell DeveloperCommented:

Okay, got it. Give me a moment, I'll make it flexible.

Chris
0
 
Chris DentPowerShell DeveloperCommented:

Oh really? Thought they were separate servers.

Well that makes life a lot easier :)

Here we go. No more credential prompts, and no more server settings, it picks up the current server name from the environmental variables, you don't need to change that one.

Chris
$SrcZone = "testsrc.com"
$DstZone = "testdst.com"
 
$Server = $Env:ComputerName
$Classes = @("MicrosoftDNS_AType", "MicrosoftDNS_CNAMEType")
 
$NewRRClass = [WMIClass]"\\$Server\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
 
ForEach ($Class in $Classes) {
  $SrcRecords = Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
    -Filter "ContainerName='$SrcZone'" | Select-Object TextRepresentation
 
  $DstRecords = Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
    -Filter "ContainerName='$DstZone'" | Select-Object TextRepresentation 
 
  ForEach ($Record in $SrcRecords) {
    $DstTextRepresentation = ($Record.TextRepresentation).Replace($SrcZone, $DstZone)
    If (!($DstRecords | ?{ $_.TextRepresentation -eq $DstTextRepresentation })) {
      $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( `
        $Server, $DstZone, $DstTextRepresentation)
    }
  }
}

Open in new window

0
 
jskfanAuthor Commented:
`I got this :

You cannot call a method on a null-valued expression.
At line:7 char:66
+     $DstTextRepresentation = ($Record.TextRepresentation).Replace( <<<< $SrcZone, $DstZone)
You cannot call a method on a null-valued expression.
At line:9 char:64
+       $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( <<<<  `
You cannot call a method on a null-valued expression.
At line:7 char:66
+     $DstTextRepresentation = ($Record.TextRepresentation).Replace( <<<< $SrcZone, $DstZone)
You cannot call a method on a null-valued expression.
At line:9 char:64
+       $NewRR = $NewRRClass.CreateInstanceFromTextRepresentation( <<<<  `on( <<<<  `
0
 
Chris DentPowerShell DeveloperCommented:

Run this on its own?

Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
    -Filter "ContainerName='$SrcZone'" | Select-Object TextRepresentation

That should return the records in the source zone... but it would seem it's not here (from the above message).

Chris
0
 
Chris DentPowerShell DeveloperCommented:

Oops, that won't work too well, $Class isn't defined. Give these a try instead please:


Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_AType" `
    -Filter "ContainerName='$SrcZone'" | Select-Object TextRepresentation

Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_CNAMEType" `
    -Filter "ContainerName='$SrcZone'" | Select-Object TextRepresentation

Chris
0
 
jskfanAuthor Commented:
I tried it by itself, it doesn't do anything.
0
 
jskfanAuthor Commented:

I found out that this command works fine and doesn't overwrite the records in the zone.
dnscmd /recordadd destinationzone @ A sourcezone.

the only thing that it can't do is to copy records like these ones:
abc      Mail Exchanger (MX)      [10]  10.230.15.20
(same as parent folder)      Mail Exchanger (MX)      [10]  10.230.15.20.
0
 
Chris DentPowerShell DeveloperCommented:

> I found out that this command works fine and doesn't overwrite the records in the zone.

Really?

Just makes an error if you run that on mine, rightly so the syntax passed with the command is rubbish ;)

> I tried it by itself, it doesn't do anything.

What value was assigned to $SrcZone? I should have noted that the value for that is still required.

Chris
0
 
jskfanAuthor Commented:
I assigned $SrcZone the source zone name I am adding to the destination zone
0
 
Chris DentPowerShell DeveloperCommented:

Hmmm something wrong there then, it should have told us about the records in the zone. Lets go with just this:


$SrcZone = "source.com"

Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_AType" `
    -Filter "ContainerName='$SrcZone'"

Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_CNAMEType" `
    -Filter "ContainerName='$SrcZone'"

Anything returned is better than nothing.

Chris
0
 
jskfanAuthor Commented:

I got this:

PS C:\Documents and Settings\administrator.mydomain> $SrcZone = "sourcezonename"
PS C:\Documents and Settings\administrator.mydomain> Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_ATy
pe" `
>>     -Filter "ContainerName='$SrcZone'"
>> Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_CNAMEType" `
>>     -Filter "ContainerName='$SrcZone'"
>>
0
 
Chris DentPowerShell DeveloperCommented:

Lets make the search less specific, if you could run:

Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_AType"

That should return all A records from all zones.

If that works, we need to confirm the zone name, because it must be wrong. If it doesn't, something is wrong with WMI which is rather more annoying :)

Chris
0
 
jskfanAuthor Commented:
Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_AType"

yes this worked
0
 
Chris DentPowerShell DeveloperCommented:

Oops forgot to reply.

If the above worked it means the zone name you're entering doesn't match the DNS servers view of it.

You can see all the possible names we can use for $SrcZone with the below.

Chris
Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_Zone" `
  | Select-Object ContainerName

Open in new window

0
 
jskfanAuthor Commented:
sorry... I am  a bit busy. I will get back with you later.
0
 
Chris DentPowerShell DeveloperCommented:

No worries, no rush :)

Chris
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 17
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now