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

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post 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.
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

That is because there is no splatting in this code.

See: help about_splatting
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Also the following

help Add-DnsServerResourceRecordA -Par TimeToLive
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post 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
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked