Create DNS records in "subdomain"

Hi,

Im trying to create DNS records in a sub zone (New domain in the GUI) using powershell.
Error message is : The zone qa.ntds.local was not found.

Have no problems with creating records in ntds.local

$zone = ‘ntds.local’ (this works)
#$zone = ‘qa.ntds.local’ (aint working)
$cnamearr = “test1”
$arr | ForEach-Object { Add-DnsServerResourceRecordA -Name ‘test1’ -IPv4Address “10.10.10.15” -ComputerName “dc-01” -ZoneName $zone}

Advice?

Regards,
Johan

the sub is actually an A record. so your hostname would be test1.qa in ntds.local

Here are three functions I wrote to find the zone a record goes into. Yes, I consistently break the law in using aliases and non-approved verbs:-)

Function get-validzone {
	
	param ($fqdn)
	
	if (Get-DnsServerZone -Name $fqdn -ComputerName yourdnsserver -ea 'silentlycontinue') { $root = 'sameasparent' } else {
		
		$a = $fqdn -split "\."
		
		$vzones = (1..($a.count - 1)) | % { ($fqdn -split "\.")[$_..$a.count] -join "." }
		
		$validatezones = foreach ($zone in $vzones) {
			
			[pscustomobject][Ordered]@{
				
				zone = $zone
				valid = [bool](Get-DnsServerZone -Name $zone -ComputerName yourdnsserver -ea 'silentlycontinue')
			}
			
		}
		
		$root = ($validatezones | ? { $_.valid -eq 'True' } | select -First 1).zone
		
	}
	
	$root
}

function Expand-IPV6 {
	
	param ($IPv6)
	
	$octets = ($ipv6 -replace '::', ':::').split(':')
	
	$results = foreach ($i in $octets) {
		$val = 0
		$r = [int]::TryParse($i, [System.Globalization.NumberStyles]::HexNumber, [System.Globalization.CultureInfo]::InvariantCulture, [ref]$val)
		('{0:X4}' -f $val)
	}
	
	$results -join ':'
	
}

Function get-validrevzone {
	
	param ($ip)
	
	if ($ip -match ':') {
		
		$fullip = expand-ipv6 $ip
		$a = ($fullip -split "(.)" -ne '') | ? {$_ -ne ':'}
		[array]::Reverse($a)
		$rev = ($a -join '.') + '.ip6.arpa'
		
		$revzones = (0..($a.count - 1)) | % { (($a)[$_..$a.count] -join ".") + '.ip6.arpa' }
		
	} else {
		
		$a = ($ip -split '\.')
		[array]::Reverse($a)
		$rev = ($a -join '.') + '.in-addr.arpa'
		
		$revzones = (0..($a.count - 1)) | % { (($a)[$_..$a.count] -join ".") + '.in-addr.arpa' }
		
	}
	
	$validatezones = foreach ($zone in $revzones) {
		[pscustomobject][Ordered]@{
			
			zone = $zone
			valid = [bool](Get-DnsServerZone -Name $zone -ComputerName yourdnsserver -ea 'silentlycontinue')
			data = ($revzones[0] -replace $zone).trimend('.')
		}
		
	}
	
	$validatezones | ? { $_.valid -eq 'True' } | select -First 1
	
	
}




###example

$zonename = get-validzone $fqdn; $name = ($fqdn -replace $zonename).trimend('.'); $ip = $item.ip


add-dnsserverresourcerecord -A -zonename $zonename -name $name -IPv4Address $ip -allowupdateany -createptr 


Get-UnApprovedVerbUser | Punish-Them…wait…dang it

:slight_smile: actually I jumped the gun… expand is approved, good guess.

Many thanks Dan!!!

Works like a charm!

Regards,
JOhan