Page 1 of 1

Powershell assistance in setting the DNS SOA record and TTL help?

Posted: Fri Apr 17, 2020 12:28 am
by ITEngineer
Hi All,

I need some help in modifying this below Powershell to add DNS server entry from a list of domains and setup the SOA TTL into 15 minutes.

So far I cannot figure it out how to:

1. Set the SOA TTL to just 15 minutes.
2. set the SOA number to be YYYYMMddd01
  1. $DomainNames = 'CorporateProduct1.com'
  2. $PrimaryDNSServer = 'PRDSVRDNS01-VM'
  3. $SecondaryDNSServer1 = 'PRDSVRDNS02-VM'
  4. $SecondaryDNSServer2 = 'PRDSVRDNS03-VM'
  5.  
  6. #Create Primary DNS Forward Lookup Zone
  7.  
  8. Add-DnsServerPrimaryZone -ComputerName $PrimaryDNSServer -Name $DomainNames -ZoneFile $DomainNames.dns -DynamicUpdate None -ResponsiblePerson "domains.$($ENV:USERDNSDOMAIN.ToLower())"
  9. Set-DnsServerPrimaryZone -ComputerName $PrimaryDNSServer -Name $DomainNames -SecureSecondaries "TransferToSecureServers" -SecondaryServers "$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer1).IPAddressToString)", "$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer2).IPAddressToString)"
  10.  
  11. # Set the Public DNS servers to replicate to
  12. Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name '@' -ZoneName $DomainNames -NS -NameServer "ns1.$ENV:USERDNSDOMAIN"
  13. Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name '@' -ZoneName $DomainNames -NS -NameServer "ns2.$ENV:USERDNSDOMAIN"
  14. Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name '@' -ZoneName $DomainNames -NS -NameServer "ns3.$ENV:USERDNSDOMAIN"
  15.  
  16. #Let the Forward lookup zones created completely
  17. Start-Sleep -Seconds 5
  18.  
  19. #Replicate the Forwardlookup zones into two additional Public DNS servers
  20. Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer1 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile "$DomainNames.dns"
  21. Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer2 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile "$DomainNames.dns"
I'm also not sure if @Splatting is even worked on the above query, hence I am asking it here for some assistance.

Thank you in advance.

Re: Powershell assistance in setting the DNS SOA record and TTL help?

Posted: Fri Apr 17, 2020 12:50 am
by jvierra
That is because there is no splatting in this code.

See: help about_splatting

Re: Powershell assistance in setting the DNS SOA record and TTL help?

Posted: Fri Apr 17, 2020 12:55 am
by jvierra
Also the following

help Add-DnsServerResourceRecordA -Par TimeToLive

Re: Powershell assistance in setting the DNS SOA record and TTL help?

Posted: Fri Apr 17, 2020 1:05 am
by ITEngineer
OK, how about making it work first before splitting it.

hence using the below one lines:

Get-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -ZoneName $DomainNames -RRType Soa | Format-List

How can I incorporate the below lines:

Code: Select all

$old = $new = ""
$old = Get-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -ZoneName $DomainNames -Name "@" -RRType SOA
$new = $old.Clone()
#$new.RecordData.SerialNumber = (Get-Date -Format 'yyyyMMdd01').ToString()
$new.RecordData = "[$((Get-Date -Format 'yyyyMMdd01').ToString())][ns1.$ENV:USERDNSDOMAIN.][domains.$($ENV:USERDNSDOMAIN.ToLower()).][1.00:00:00][01:00:00][00:15:00][00:10:00]"
$new.TimeToLive = 00:15:00
Set-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -ZoneName $DomainNames -OldInputObject $old -NewInputObject $new

Re: Powershell assistance in setting the DNS SOA record and TTL help?

Posted: Fri Apr 17, 2020 1:20 am
by jvierra