Bulk DNS modify | TXT record description

Welcome Forums General PowerShell Q&A Bulk DNS modify | TXT record description

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 months, 3 weeks ago.

  • Author
    Posts
  • #162822

    Participant
    Topics: 115
    Replies: 244
    Points: 142
    Rank: Participant

    I got this code working to change the Description field of a DNS txt RR:

    $oldvalue = Get-DnsServerResourceRecord -ZoneName ZoneName.com -ComputerName DNSSERVER -RRType Txt -Name _dmarc
    $newvalue = Get-DnsServerResourceRecord -ZoneName ZoneName.com -ComputerName DNSSERVER -RRType Txt -Name _dmarc
    $newvalue.RecordData.DescriptiveText = “v=DMARC1; p=none; fo=1; rua=mailto:dmarc_rua@emaildefense.point.com; ruf=mailto:dmarc_ruf@emaildefense.point.com”
    Set-DnsServerResourceRecord -ZoneName ZoneName.com -ComputerName DNSSERVER -OldInputObject $oldvalue -NewInputObject $newvalue

    ...and I have a csv structured like this:

    DomainName,DMARCRecordName,NewDMARCRecord
    contoso.com.hk,_dmarc,"v=DMARC1; p=none; fo=1; rua=mailto:dmarc_rua@emaildefense.point.com; ruf=mailto:dmarc_ruf@emaildefense.point.com"

    ...How would you create a for each loop to set all my new descriptions?

  • #162846

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    you're almost done.

    you would use Import-Csv with a ForEach-object in the pipeline.

    Import-Csv -Path  | ForEach-Object -Process {
    $oldvalue = Get-DnsServerResourceRecord -ZoneName ZoneName.com -ComputerName DNSSERVER -RRType Txt -Name $_.DMARRecordName
    $NewValue = Get-DnsServerResourceRecord -ZoneName ZoneName.com -ComputerName DNSSERVER -RRType Txt -Name $_.DMARRecordName
    # $_ has all the information you have in CSV. you can add the set dns rr code below.
    }
    
    • #162981

      Participant
      Topics: 115
      Replies: 244
      Points: 142
      Rank: Participant

      Thank you...I got this working then with this:

      Import-Csv -Path .\DMARC.csv  | ForEach-Object -Process {
      $oldvalue = Get-DnsServerResourceRecord -ZoneName $_.DomainName -ComputerName DNSSERVER-RRType Txt -Name _dmarc
      $NewValue = Get-DnsServerResourceRecord -ZoneName $_.DomainName -ComputerName DNSSERVER-RRType Txt -Name _dmarc
      $newvalue.RecordData.DescriptiveText = $_."NewDMARCRecord”
      Set-DnsServerResourceRecord -ZoneName $_.DomainName -ComputerName DNSSERVER-OldInputObject $oldvalue -NewInputObject $newvalue
      }

      I'd like help with a validation step, exporting the changed descriptions to a csv and tried this:

      Import-Csv -Path .\DMARC.csv  | ForEach-Object -Process {
      $CurrentValue = Get-DnsServerResourceRecord -ZoneName $_.DomainName -ComputerName DNSSERVER-RRType Txt -Name _dmarc
      $CurrentValue.RecordData.DescriptiveText | Export-Csv -Path .\CurrentValue.csv -NoTypeInformation < ---- wrong
      ### How do I then output all the changed descriptions to a .csv?
      

      }

You must be logged in to reply to this topic.