# Powershell to update DNS SOA & TTL modification help?

**URL:** <https://forums.powershell.org/t/powershell-to-update-dns-soa-ttl-modification-help/14185>\
**Category:** PowerShell Help\
**Created:** [April 17, 2020, 1:57am UTC](https://forums.powershell.org/t/powershell-to-update-dns-soa-ttl-modification-help/14185 "2020-04-17T01:57:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![albertwt](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/albertwt/32/2550_2.png) [@albertwt](https://forums.powershell.org/u/albertwt)\
**Post date:** [April 17, 2020, 1:57am UTC](https://forums.powershell.org/t/powershell-to-update-dns-soa-ttl-modification-help/14185/1 "2020-04-17T01:57:03Z")

</div>

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

```
$DomainNames = 'CorporateProduct1.com'
$PrimaryDNSServer = 'PRDSVRDNS01-VM'
$SecondaryDNSServer1 = 'PRDSVRDNS02-VM'
$SecondaryDNSServer2 = 'PRDSVRDNS03-VM'

#Create Primary DNS Forward Lookup Zone

Add-DnsServerPrimaryZone -ComputerName $PrimaryDNSServer -Name $DomainNames -ZoneFile $DomainNames.dns -DynamicUpdate None -ResponsiblePerson “domains.$($ENV:USERDNSDOMAIN.ToLower())”  
Set-DnsServerPrimaryZone -ComputerName $PrimaryDNSServer -Name $DomainNames -SecureSecondaries “TransferToSecureServers” -SecondaryServers “$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer1).IPAddressToString)”, “$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer2).IPAddressToString)”

# Set the Public DNS servers to replicate to

Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name ‘@’ -ZoneName $DomainNames -NS -NameServer “ns1.$ENV:USERDNSDOMAIN”  
Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name ‘@’ -ZoneName $DomainNames -NS -NameServer “ns2.$ENV:USERDNSDOMAIN”  
Add-DnsServerResourceRecord -ComputerName $PrimaryDNSServer -Name ‘@’ -ZoneName $DomainNames -NS -NameServer “ns3.$ENV:USERDNSDOMAIN”

#Let the Forward lookup zones created completely  
Start-Sleep -Seconds 5

#Replicate the Forwardlookup zones into two additional Public DNS servers  
Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer1 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile “$DomainNames.dns”  
Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer2 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile “$DomainNames.dns”
```

I wonder if @Splatting is even worked on the above query, hence I am asking it here.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [April 17, 2020, 3:26am UTC](https://forums.powershell.org/t/powershell-to-update-dns-soa-ttl-modification-help/14185/2 "2020-04-17T03:26:37Z")

</div>

Splatting will make this a whole lot more readable.

Also notice that

```
"$([System.Net.Dns]::GetHostAddresses($SecondaryDNSServer1).IPAddressToString)"
```

may return a bunch of IPv4 AND IPv6 addresses

Finally, the last lines need to be updated like:

```
#Replicate the Forwardlookup zones into two additional Public DNS servers
Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer1 -MasterServers ([System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString) -Name $DomainNames -ZoneFile "$DomainNames.dns"
Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer2 -MasterServers ([System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString) -Name $DomainNames -ZoneFile "$DomainNames.dns"
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/powershell-to-update-dns-soa-ttl-modification-help/14185/3 "2024-05-16T20:29:53Z")

</div>


