1
Vote

"Set-DnsZoneTransfer : Only valid for Primary Zones" error again

description

Hi,

I'm facing "Set-DnsZoneTransfer : Only valid for Primary Zones" error:

$ZoneName = "Secondary-Zone-0001"
[array]$NewDnsZoneTransferSecondaryServersIP = "10.7.64.55"

$DNSZoneIdentity = (Get-DnsZone -Name $ZoneName).Identity

Set-DnsZoneTransfer -Identity $DNSZoneIdentity -Zonetransfer Any -SecondaryServers $NewDnsZoneTransferSecondaryServersIP
Set-DnsZoneTransfer : Only valid for Primary ZonesAt line:13 char:1
+ Set-DnsZoneTransfer -Identity $DNSZoneIdentity -Zonetransfer Any -SecondaryServe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (DnsShell.PowerS...anagementCmdlet:RuntimeType) [Set-DnsZoneTransfer], PSInvalidOperationException
    + FullyQualifiedErrorId : InvalidOperation,DnsShell.PowerShell.CmdLet.SetDnsZoneTransfer
 
Any way of fixing this or use workaround ?

comments

ALIENQuake wrote Apr 2, 2014 at 11:33 AM

I've tested it on:
Server 2008 R2, PS 2.0, .NET 40, DNSShell 0.4.2
Server 2008 R2, PS 3.0, .NET 4.5.1, DNSShell 0.4.4

TeflonJim wrote Apr 2, 2014 at 12:55 PM

Work-around:
$NewDnsZoneTransferSecondaryServersIP = "10.7.64.55"

$Zone = Get-DnsZone "Secondary-Zone-0001"
$ZoneWmiObject = [WMI]($Zone.Identity)

$inParams = [Management.ManagementBaseObject]$ZoneWmiObject.GetMethodParameters("ResetSecondaries")

# Allow transfer to a list of servers (2), Any is 0.
$inParams["SecureSecondaries"] = 2
# This must be an array, this ensures that is so.
$inParams["SecondaryServers"] = @($NewDnsZoneTransferSecondaryServersIP)

# Preserve the notify setting from the original zone
$inParams["Notify"] = $ZoneWmiObject.Notify
# And preserve the notify list
if ($ZoneWmiObject.NotifyServers) {
  $inParams["NotifyServers"] = $ZoneWmiObject.NotifyServers
}
# Apply the change. Nothing back is a good thing. Verify the change by calling Get-DnsZone again.
$ZoneWmiObject.InvokeMethod("ResetSecondaries", $inParams, $null)
Cheers,

Chris

ALIENQuake wrote Apr 2, 2014 at 2:02 PM

OMG THANK YOU! Five star for instant help!