Bulk DNS modify | TXT record description

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

Viewing 1 reply thread
  • Author
    Posts
    • #162822
      Participant
      Topics: 120
      Replies: 260
      Points: 238
      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:[email protected]; ruf=mailto:[email protected]”
      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:[email protected]; ruf=mailto:[email protected]"

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

    • #162846
      Senior Moderator
      Topics: 9
      Replies: 1236
      Points: 4,443
      Helping Hand
      Rank: Community Hero

      you’re almost done.

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

      Import-Csv -Path <your 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: 120
        Replies: 260
        Points: 238
        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?
        

        }

Viewing 1 reply thread
  • The topic ‘Bulk DNS modify | TXT record description’ is closed to new replies.