How can I combine Add-DnsServerResourceRecordA & Add-DnsServerResourceRecordPTR cmdlets to automate creating DNS records?


powershell gurus,

we running windows server 2012 r2 powershell v4.0 , want take advantage of new add-dnsserverresourcerecorda and  add-dnsserverresourcerecordptr cmdlets (and remove-dnsserverresourcerecord) automate as possible creation/deletion of statically configured dns records.

question: how can combine these 2 cmdlets run create dns 'a' , dns 'ptr' records in 1 long cmdlet?  how make can run both of these below 1 cmdlet?

add-dnsserverresourcerecorda -name "hostname123" -zonename "contoso.com" -allowupdateany -ipv4address "192.168.0.123" -timetolive 01:00:00

add-dnsserverresourcerecordptr -name "123" -zonename "0.168.192.in-addr.arpa" -allowupdateany -timetolive 01:00:00 -agerecord -ptrdomainname "hostname123.contoso.com"  

as develop our competence powershell, make can use (get-content) import dns entries .csv file as possible automate creation of dns 'a' , 'ptr' records.  how can this?

thank insight , ideas!

cheers!


matt

i don't see reason why can't run each of these cmdlets separately. each cmdlet requires different pieces of information , trying make 1 long cmdlet isn't going much. in fact, it'll make more difficult. now, storing information in csv facilitate creating these quicker - wonderful idea.

start csv named dnsrecords.csv has format seen below. have included representation in both excel , in programmer's notepad.

this example script below hasn't been tested. has been designed one, import data in csv file variable, , two, iterate through each record store in variable. looks @ each entry determines type of record (a or ptr) , heads correct way proper record created. best of luck , hope helpful.

$dnsrecords = import-csv -path 'c:\users\tommymaynard\desktop\dnsrecords.csv' foreach ($entry in $dnsrecords) {      if ($entry.type -eq 'a') {         add-dnsserverresourcerecorda -name $entry.name -zonename $entry.zonename -allowupdateany -ipv4address $entry.ipv4address -timetolive $entry.timetolive         write-output -verbose "added record $($entry.name)"      } elseif ($entry.type -eq 'ptr') {         add-dnsserverresourcerecordptr -name $entry.name -zonename $entry.zonename -allowupdateany -timetolive $entry.timetolive -agerecord -ptrdomainname $entry.ptrdomainname         write-output -verbose "added ptr record $($entry.name)"      } else {         write-output -verbose 'unable determine dns record type.'     }  }



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS