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
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Fri Apr 17, 2020 12:28 am
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'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
Post
by jvierra » Fri Apr 17, 2020 12:50 am
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
Post
by jvierra » Fri Apr 17, 2020 12:55 am
Also the following
help Add-DnsServerResourceRecordA -Par TimeToLive
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Fri Apr 17, 2020 1:05 am
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 */
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