jskfan
asked on
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
ASKER
is it possible if they have different names ?
It's not "test.com" in both cases? DNS isn't case sensitive if that's the only difference.
Chris
ASKER
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
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
ASKER
that's english.
Okay, well I'll get on with that first thing in the morning unless something blows up here :)
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I pasted your code to a notepad and created myscript.vbs file.
I am getting this error:
Script C:\document and settings\administrator.myd
line:1
char:1
Error:Invalid Charachter
code:800A0408
Source:Microsoft VBScript compilation error
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
> 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
ASKER
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.myc ompany> $SrcServer = "myDNSserver.mycompany.com "
PS C:\Documents and Settings\administrator.myc ompany> $SrcCredential = "mydomain\myuseraccount"
PS C:\Documents and Settings\administrator.myc ompany> $SrcZone = "mycompanyemailservices.ne t"
PS C:\Documents and Settings\administrator.myc ompany>
PS C:\Documents and Settings\administrator.myc ompany> $DstServer = "myDNSserver"
PS C:\Documents and Settings\administrator.myc ompany> $DstZone = "mycompany.com"
PS C:\Documents and Settings\administrator.myc ompany>
PS C:\Documents and Settings\administrator.myc ompany> $Classes = @("MicrosoftDNS_AType", "MicrosoftDNS_CNAMEType")
PS C:\Documents and Settings\administrator.myc ompany>
PS C:\Documents and Settings\administrator.myc ompany> $NewRRClass = [WMIClass]"\\$DstServer\ro ot\Microso ftDNS:Micr osoft
ResourceRecord"
PS C:\Documents and Settings\administrator.myc ompany>
PS C:\Documents and Settings\administrator.myc ompany> 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.TextRepresentatio n).Replace ($SrcZone, $DstZone)
>>
>> If (!($DstRecords | ?{ $_.TextRepresentation -eq $DstTextRepresentation })) {
>> $NewRR = $NewRRClass.CreateInstance FromTextRe presentati on( `
>> $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.TextRepresentatio n).Replace ( <<<< $SrcZone, $DstZone)
Exception calling "CreateInstanceFromTextRep resentatio n" : "Invalid parameter "
At line:11 char:64
+ $NewRR = $NewRRClass.CreateInstance FromTextRe presentati on( <<<< `
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.TextRepresentatio n).Replace ( <<<< $SrcZone, $DstZone)
Exception calling "CreateInstanceFromTextRep resentatio n" : "Invalid parameter "
At line:11 char:64
+ $NewRR = $NewRRClass.CreateInstance FromTextRe presentati on( <<<< `
PS C:\Documents and Settings\administrator.myc ompany>
Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
ResourceRecord"
PS C:\Documents and Settings\administrator.myc
PS C:\Documents and Settings\administrator.myc
>>
>> $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.TextRepresentatio
>>
>> If (!($DstRecords | ?{ $_.TextRepresentation -eq $DstTextRepresentation })) {
>> $NewRR = $NewRRClass.CreateInstance
>> $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.TextRepresentatio
Exception calling "CreateInstanceFromTextRep
At line:11 char:64
+ $NewRR = $NewRRClass.CreateInstance
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.TextRepresentatio
Exception calling "CreateInstanceFromTextRep
At line:11 char:64
+ $NewRR = $NewRRClass.CreateInstance
PS C:\Documents and Settings\administrator.myc
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
ASKER
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.
Okay, got it. Give me a moment, I'll make it flexible.
Chris
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)
}
}
}
ASKER
`I got this :
You cannot call a method on a null-valued expression.
At line:7 char:66
+ $DstTextRepresentation = ($Record.TextRepresentatio n).Replace ( <<<< $SrcZone, $DstZone)
You cannot call a method on a null-valued expression.
At line:9 char:64
+ $NewRR = $NewRRClass.CreateInstance FromTextRe presentati on( <<<< `
You cannot call a method on a null-valued expression.
At line:7 char:66
+ $DstTextRepresentation = ($Record.TextRepresentatio n).Replace ( <<<< $SrcZone, $DstZone)
You cannot call a method on a null-valued expression.
At line:9 char:64
+ $NewRR = $NewRRClass.CreateInstance FromTextRe presentati on( <<<< `on( <<<< `
You cannot call a method on a null-valued expression.
At line:7 char:66
+ $DstTextRepresentation = ($Record.TextRepresentatio
You cannot call a method on a null-valued expression.
At line:9 char:64
+ $NewRR = $NewRRClass.CreateInstance
You cannot call a method on a null-valued expression.
At line:7 char:66
+ $DstTextRepresentation = ($Record.TextRepresentatio
You cannot call a method on a null-valued expression.
At line:9 char:64
+ $NewRR = $NewRRClass.CreateInstance
Run this on its own?
Get-WMIObject -Namespace "root\MicrosoftDNS" -Class $Class `
-Filter "ContainerName='$SrcZone'"
That should return the records in the source zone... but it would seem it's not here (from the above message).
Chris
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'"
Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_CNAMEType" `
-Filter "ContainerName='$SrcZone'"
Chris
ASKER
I tried it by itself, it doesn't do anything.
ASKER
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.
> 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
ASKER
I assigned $SrcZone the source zone name I am adding to the destination zone
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
ASKER
I got this:
PS C:\Documents and Settings\administrator.myd
PS C:\Documents and Settings\administrator.myd
pe" `
>> -Filter "ContainerName='$SrcZone'"
>> Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_CNAMEType" `
>> -Filter "ContainerName='$SrcZone'"
>>
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
ASKER
Get-WMIObject -Namespace "root\MicrosoftDNS" -Class "MicrosoftDNS_AType"
yes this worked
yes this worked
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
ASKER
sorry... I am a bit busy. I will get back with you later.
No worries, no rush :)
Chris
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