From 7c5ba1f5d4f017143c30d3a7a26ca4a558968bd5 Mon Sep 17 00:00:00 2001 From: Zak Bearman Date: Wed, 21 Jan 2026 01:27:05 +0000 Subject: [PATCH] Add DNS-Maker.ps1 --- DNS-Maker.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 DNS-Maker.ps1 diff --git a/DNS-Maker.ps1 b/DNS-Maker.ps1 new file mode 100644 index 0000000..bc773bb --- /dev/null +++ b/DNS-Maker.ps1 @@ -0,0 +1,33 @@ +# Variables +$CsrFolder = "C:\Temp\CSRs" # Path to folder with CSR files +$DnsZone = "record.domain.govt.nz" # Your DNS zone (AD-integrated) +$TargetIP = "managementboxIP" # The IP for all A records +$DnsServer = "DC01.example.local" # AD Domain Controller / DNS server + +# Loop through CSR files +Get-ChildItem -Path $CsrFolder -Filter *.csr | ForEach-Object { + # Get just the file name without extension + $fqdn = $_.BaseName.Trim() + Write-Host "Processing $fqdn ..." + + try { + # If the filename is a full FQDN, strip the zone name + if ($fqdn.ToLower().EndsWith(".$($DnsZone.ToLower())")) { + $hostname = $fqdn.Substring(0, $fqdn.Length - $DnsZone.Length - 1) + } else { + $hostname = $fqdn + } + + Write-Host " -> Adding DNS A record for $hostname.$DnsZone -> $TargetIP" + + Add-DnsServerResourceRecordA ` + -Name $hostname ` + -ZoneName $DnsZone ` + -IPv4Address $TargetIP ` + -ComputerName $DnsServer ` + -ErrorAction Stop + + } catch { + Write-Warning "Could not add DNS record for $fqdn : $_" + } +} \ No newline at end of file