Create DNS records in "subdomain"

Welcome Forums General PowerShell Q&A Create DNS records in "subdomain"

Viewing 4 reply threads
  • Author
    Posts
    • #61875
      Participant
      Topics: 5
      Replies: 13
      Points: 0
      Rank: Member

      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

    • #61888
      Participant
      Topics: 18
      Replies: 575
      Points: 42
      Rank: Member

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

      • #61914
        Participant
        Topics: 5
        Replies: 13
        Points: 0
        Rank: Member

        Many thanks Dan!!!

        Works like a charm!

        Regards,
        JOhan

    • #61900
      Participant
      Topics: 18
      Replies: 575
      Points: 42
      Rank: Member

      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 
      
      
      
    • #61903
      Participant
      Topics: 12
      Replies: 1642
      Points: 2,660
      Helping Hand
      Rank: Community Hero

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

    • #61906
      Participant
      Topics: 18
      Replies: 575
      Points: 42
      Rank: Member

      🙂 actually I jumped the gun.. expand is approved, good guess.

Viewing 4 reply threads
  • The topic ‘Create DNS records in "subdomain"’ is closed to new replies.