Skip to content

Instantly share code, notes, and snippets.

@jbilinski
Last active October 8, 2019 04:42
Show Gist options
  • Save jbilinski/fa810183c09d0d2f9d54d2dd6a00ff13 to your computer and use it in GitHub Desktop.
Save jbilinski/fa810183c09d0d2f9d54d2dd6a00ff13 to your computer and use it in GitHub Desktop.
copy-dns-from-pfsense-unbound-to-windows
#requires -Version 4.0 -Modules DnsServer
<#
.Synopsis
Copy Unbound DNS records from pfSense to MS DNS server
.DESCRIPTION
Facilitates movement from Unbound on pfSense to MS DNS services.
Function recreates A and CNAME records from pfSense backup in a MS Server DNS zone.
*Tested with pfSense version 2.3.2 and Server 2016
.EXAMPLE
Import-pfSUnDNS -pfSBackupFile '.\pfsBackupConfig.xml' -Domain 'hq.vulcan.com' -DNSSrv 'msdc1.west.vulcan.com'
#>
function Import-pfSUnDNS
{
[CmdletBinding()]
[OutputType([int])]
Param
(
# Full path of PFSense xml-formatted backup file
[Parameter(Mandatory = $true)]$pfSBackupFile,
# DNS domain name filter
[Parameter(Mandatory = $true)][string] $Domain,
# Target DNS server
[string] $DNSSrv
)
Begin
{
[xml]$pfConfXML = Get-Content $pfSBackupFile -Encoding UTF8
}
Process
{
$pfConfXML.pfsense.unbound.hosts.ForEach({
$thishost = $_
if ($thishost.domain -like $Domain)
{
Write-Verbose -Message "creating`tA record`tName:$($thishost.host).$($Domain)`t`tIP Address:$($thishost.ip)"
Add-DnsServerResourceRecord -A -IPv4Address $($thishost.ip) -Name $($thishost.host) -ZoneName $Domain -ComputerName $DNSSrv -CreatePtr
if ($thishost.aliases)
{
forEach ($cname in $($thishost.aliases))
{
Write-Verbose -Message "Creating`tCNAME`t`tAlias:$($cname.item.host)`t`t`tHost:$($thishost.host).$($Domain)"
Add-DnsServerResourceRecord -CName -HostNameAlias "$($thishost.host).$($Domain)" -Name $($cname.item.host) -ZoneName $Domain -ComputerName $DNSSrv
}
}
}
})
}
End
{
Write-Verbose -Message 'Script complete.'
}
}
# SIG # Begin signature block
# MIIYZwYJKoZIhv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RriOe
# Dh4CWM4wJENuzzr6pNXygH54aLttpf1B4jaBnh8YG8RNJTKamaMZqDCBflHFSBy/
# Z1XSKhRGHMBzo1s=
# SIG # End signature block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment