32 lines
1.1 KiB
PowerShell
32 lines
1.1 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 -notcontains $IPv4Address.IPAddressToString) {
|
|
throw "$RecordName.$ZoneName already exists with a different address: $($current -join ', ')."
|
|
}
|
|
}
|
|
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)
|
|
}
|