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.
Locked
User avatar
ITEngineer
Posts: 208
Joined: Wed Oct 12, 2011 10:52 am

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.  
  3. $PrimaryDNSServer = 'PRDSVRDNS01-VM'
  4.  
  5. $SecondaryDNSServer1 = 'PRDSVRDNS02-VM'
  6.  
  7. $SecondaryDNSServer2 = 'PRDSVRDNS03-VM'
  8.  
  9.  
  10.  
  11. #Create Primary DNS Forward Lookup Zone
  12.  
  13.  
  14.  
  15. Add-DnsServerPrimaryZone -ComputerName $PrimaryDNSServer -Name $DomainNames -ZoneFile $DomainNames.dns -DynamicUpdate None -ResponsiblePerson "domains.$($ENV:USERDNSDOMAIN.ToLower())"
  16.  
  17. Set-DnsServerPrimaryZone -ComputerName $PrimaryDNSServer -Name $DomainNames -SecureSecondaries "TransferToSecureServers" -SecondaryServers "$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer1).IPAddressToString)", "$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer2).IPAddressToString)"
  18.  
  19.  
  20.  
  21. # Set the Public DNS servers to replicate to
  22.  
  23. Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name '@' -ZoneName $DomainNames -NS -NameServer "ns1.$ENV:USERDNSDOMAIN"
  24.  
  25. Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name '@' -ZoneName $DomainNames -NS -NameServer "ns2.$ENV:USERDNSDOMAIN"
  26.  
  27. Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name '@' -ZoneName $DomainNames -NS -NameServer "ns3.$ENV:USERDNSDOMAIN"
  28.  
  29.  
  30.  
  31. #Let the Forward lookup zones created completely
  32.  
  33. Start-Sleep -Seconds 5
  34.  
  35.  
  36.  
  37. #Replicate the Forwardlookup zones into two additional Public DNS servers
  38.  
  39. Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer1 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile "$DomainNames.dns"
  40.  
  41. 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: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 208
Joined: Wed Oct 12, 2011 10:52 am

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 */


Locked