question

GlennMaxwell-2309 avatar image
0 Votes"
GlennMaxwell-2309 asked GitaraniSharmaMSFT-4262 edited

Records creation

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-active-directorywindows-server-2016windows-dhcp-dnswindows-server-management
record.jpg (27.3 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Is there any update? Have you got a chance to verify the below suggestion?
Please feel free to let us know if more assistance is needed. If the reply is helpful, please “Accept Answer” to help other community members find it more easily,

0 Votes 0 ·

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.