Records creation

Glenn Maxwell 12,871 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 for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
Windows for business | Windows Server | User experience | Other
{count} votes

Accepted answer
  1. Anonymous
    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.