Records creation

Glenn Maxwell 11,941 Reputation points
2021-07-06T13:27:52.447+00:00

Hi All

I want to create DNS records i.e host records and alias records by importing csv file, experts please guide me with the syntax.
using the below syntaxes i can create records but how do i import csv file and create it also i want to create ptr recording during host record creation.

Add-DnsServerResourceRecordA -ZoneName contoso.com -IPv4Address 192.168.5.10
Add-DnsServerResourceRecordCName -ZoneName contoso.com -HostNameAlias "server01.contoso.com" -Name "fin1"

my csv file is in below format

112192-record.jpg

Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,538 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,736 questions
Windows DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,043 questions
Windows Server Management
Windows Server Management
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Management: The act or process of organizing, handling, directing or controlling something.
442 questions
{count} votes

Accepted answer
  1. Ian Xue 38,631 Reputation points Microsoft Vendor
    2021-07-07T02:32:59.683+00:00

    Hi,

    Please try the below script.

    $file = "C:\temp\records.csv"  
    Import-Csv -Path $file | ForEach-Object {  
        if ($_.RecordType -eq "A") {  
            Add-DnsServerResourceRecordA -ZoneName $_.Zone -IPv4Address $_."IP Address" -Name $_.Name  
        }  
        elseif ($_.RecordType -eq "CNAME"){  
            Add-DnsServerResourceRecordCName -ZoneName $_.Zone -HostNameAlias $_.RecordData -Name $_.Name   
        }  
    }   
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.