35 lines
1.4 KiB
PowerShell
35 lines
1.4 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[string]$ZoneName = 'lci.lasalle.mx',
|
|
[string]$RecordName = 'sgu-auth',
|
|
[ipaddress]$IPv4Address = '192.168.50.10',
|
|
|
|
[ipaddress[]]$ExternalForwarders = @()
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$existing = Get-DnsServerResourceRecord -ZoneName $ZoneName -Name $RecordName -RRType A -ErrorAction SilentlyContinue
|
|
if ($existing) {
|
|
$current = @($existing.RecordData.IPv4Address.IPAddressToString)
|
|
if ($current.Count -ne 1 -or $current[0] -ne $IPv4Address.IPAddressToString) {
|
|
# The fixed lab address is an explicit bootstrap input and may change
|
|
# when the server is rebuilt. Replace only this exact A record set.
|
|
$existing | Remove-DnsServerResourceRecord -ZoneName $ZoneName -Force
|
|
Add-DnsServerResourceRecordA -ZoneName $ZoneName -Name $RecordName -IPv4Address $IPv4Address
|
|
}
|
|
}
|
|
else {
|
|
Add-DnsServerResourceRecordA -ZoneName $ZoneName -Name $RecordName -IPv4Address $IPv4Address
|
|
}
|
|
|
|
if ($ExternalForwarders.Count -gt 0) {
|
|
Set-DnsServerForwarder -IPAddress $ExternalForwarders -UseRootHint $false
|
|
Clear-DnsServerCache -Force
|
|
Clear-DnsClientCache
|
|
}
|
|
|
|
[pscustomobject]@{
|
|
BrokerRecord = Resolve-DnsName "$RecordName.$ZoneName" | Select-Object Name, Type, IPAddress
|
|
ExternalForwarders = @(Get-DnsServerForwarder | Select-Object -ExpandProperty IPAddress | ForEach-Object IPAddressToString)
|
|
}
|