Adds one A record to a zone and requests the matching PTR where a reverse zone exists. An existing record is reported with the address it points to and left untouched rather than duplicated, and the write is verified afterwards, with the two usual causes of failure named in the message: a secondary zone, or missing permissions.
powershell
# Create a DNS A Record
# Single use case: add one A record (with PTR if the reverse zone exists)
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
# --- Parameters (replace via ServerEngine API parameters if needed) ---
$RecordName = "newhost"
$ZoneName = "example.local"
$IPAddress = "10.0.0.50"
if (-not (Get-Module -ListAvailable -Name DnsServer)) {
Write-Log "DnsServer module not available - is the DNS role installed on this host?"
return
}
$zone = Get-DnsServerZone -Name $ZoneName -ErrorAction SilentlyContinue
if ($null -eq $zone) { Write-Log "Zone not found on this server: $ZoneName"; return }
$existing = Get-DnsServerResourceRecord -ZoneName $ZoneName -Name $RecordName -RRType A -ErrorAction SilentlyContinue
if ($existing) {
$ips = ($existing | ForEach-Object { $_.RecordData.IPv4Address.IPAddressToString }) -join ", "
Write-Log "Record $RecordName.$ZoneName already exists -> $ips - nothing changed."
return
}
Add-DnsServerResourceRecordA -ZoneName $ZoneName -Name $RecordName -IPv4Address $IPAddress -CreatePtr -ErrorAction SilentlyContinue
$verify = Get-DnsServerResourceRecord -ZoneName $ZoneName -Name $RecordName -RRType A -ErrorAction SilentlyContinue
if ($verify) {
Write-Log "A record created: $RecordName.$ZoneName -> $IPAddress (PTR requested where reverse zone exists)."
} else {
Write-Log "WARNING: record was not created - check zone type (must be primary) and permissions."
}Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Windows Server Roles
Report Installed Server Roles with PowerShell
2026-08-17Report DHCP Scope Utilization with PowerShell
2026-08-17Clear the DNS Server Cache with PowerShell
2026-08-17Find the Largest Files in a Folder with PowerShell
2026-08-17Get Folder Sizes with PowerShell
2026-08-17Report SMB Shares and Permissions with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.