From 498f732d8090485672fff67a1a7e03a3896bdcc8 Mon Sep 17 00:00:00 2001 From: Rephl3x Date: Wed, 24 Sep 2025 01:00:44 +0000 Subject: [PATCH] for WACS create a folder and put all CSR's in it. This will read the name of CSR file in FQDN --- Stacker.ps1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Stacker.ps1 diff --git a/Stacker.ps1 b/Stacker.ps1 new file mode 100644 index 0000000..ac1dabc --- /dev/null +++ b/Stacker.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 : $_" + } +}