Public/Import-DNSFromCSV.ps1

Function Import-DNSFromCSV {
    <#
        .SYNOPSIS
            Import DNS-Records from CSV
        .DESCRIPTION
            Import DNS-Records from CSV
        .Parameter Path
            .csv file with records
 
        .Parameter zone
            zone-name for DNS
        .EXAMPLE
            PS C:\> Import-DNSFromCSV -Path dns.csv -zone example.com
            Imports DNS-records from dns.csv to the example.com zone
 
            The CSV needs to look like this:
            Computer,IP
            Computer01,192.168.0.1
            Computer02,192.168.0.2
            Computer03,192.168.0.3
        .Inputs
            None
        .Outputs
            Microsoft.Management.Infrastructure.CimInstance#DnsServerResourceRecord[]
                http://msdn.microsoft.com/library/windows/desktop/hh832775.aspx
 
        .LINK
            about_functions_advanced
 
        .LINK
            about_CommonParameters
        .LINK
            Add-DnsServerResourceRecordA
    #>

    [CmdletBinding(
        ConfirmImpact = 'Medium',
        SupportsShouldProcess = $true
    )]
    Param (
        [Parameter(
            Mandatory = $true,
            HelpMessage = 'Provide csv for import'
        )]
        [ValidateScript( { Test-IsCSV $_ })]
        [Alias('File')]
        [System.IO.FileInfo]$Path,
        [Parameter(
            Mandatory = $true,
            ValueFromPipeline = $true,
            HelpMessage = 'Provide zonename to import csv into'
        )]
        $Zone
    )

    Begin {
        If (-not $PSBoundParameters.ContainsKey('Verbose')) {
            $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference')
        }
        If (-not $PSBoundParameters.ContainsKey('ErrorAction')) {
            $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference')
        }
    }
    Process {
        If ($PSCmdlet.ShouldProcess('DNS', "Import $Path into $Zone")) {
            Try {
                Import-CSV -Path $Path | ForEach-Object {
                    Add-DnsServerResourceRecordA -Name $_.Computer -ZoneName $Zone -IPv4Address $_.IP
                }
            } Catch {
                Write-Warning $_.Exception.Message
                $Error[0]
            }
        }
    }
    End {
    }
}
Set-Alias -Name Set-DNSFromCSV -Value Import-DNSFromCSV -Description "Import DNS from CSV-file" -Option ReadOnly -PassThru -ErrorAction SilentlyContinue