Forum Discussion
Arlecchino
May 07, 2025Copper Contributor
need to create a PTR record via PS | Need your help !
Hello dear community, I am trying to update PTR records in my DNS manager using PowerShell script and I am using the below script, it works only when a reverse zone is already existing but I have a ...
Andres-Bohren
May 08, 2025Iron Contributor
Hi Arlecchino
You check if the Zone exists, but do not acutally create one if it does not exist...
# Check if reverse zone exists
$zoneExists = Get-DnsServerZone -Name $reverseZone -ComputerName $DnsServer -ErrorAction SilentlyContinue
if (-not $zoneExists) {
throw "Reverse zone $reverseZone does not exist on server $DnsServer"
}
Arlecchino
May 09, 2025Copper Contributor
Hi Andres-Bohren,
Probably you missed this part of the script. it is in else part of the script
# Create new record - FIXED SECTION
Write-Host " [CREATE] Adding new PTR record for $ptrName pointing to $hostname"
# Explicitly create the record object
$newPtrRecord = @{
ZoneName = $reverseZone
Name = $ptrName
PtrDomainName = $hostname
ComputerName = $DnsServer
ErrorAction = 'Stop'
}