Fixing reverse DNS

Welcome Forums General PowerShell Q&A Fixing reverse DNS

Viewing 3 reply threads
  • Author
    Posts
    • #271759
      Participant
      Topics: 2
      Replies: 1
      Points: 16
      Rank: Member

      Hi, I’m trying to fix our missing DNS Reverse lookups with Powershell.

      I have a CSV file with the headers ‘Name’ and last two octets of an ‘IP’ address that looks like below:

      name,ip
      workstation1.famoso.com,169.120
      workstation2.famoso.com,169.121

      My goal is to reverse the IP value so it displays as 120.169

      Then create a new object with the Name and reversed IP.

      name,iprev
      workstation1.famoso.com,120.169
      workstation2.famoso.com,121.169

      Then import the Name and reversed IP using the command below


      The problem I am having is creating the new object with Name and reversed IP so I can capture that in a variable.

      I figured out how to reverse the IP:


      How can i create a new object with Name and IPrev that looks like below?

      name,IPrev
      workstation1.famoso.com,120.169
      workstation2.famoso.com,121.169

      I would like to capture that to a variable $servers1 and | to Add-DnsServerResourceRecordPtr

      ****the commands below can add, get, and remove a single PTR record from DNS

      • This topic was modified 2 weeks, 2 days ago by Prashant S.
      • This topic was modified 2 weeks, 2 days ago by Prashant S.
      • This topic was modified 2 weeks, 2 days ago by Prashant S. Reason: typo
    • #271984
      Participant
      Topics: 5
      Replies: 170
      Points: 656
      Helping Hand
      Rank: Major Contributor

      In this example I used the -split operator to split the octets into an array then reversed the last two.  The backslash is required because we want the literal . and it is a regular expression (. is any character).

      • This reply was modified 2 weeks, 1 day ago by Mike R..
    • #272050
      Participant
      Topics: 9
      Replies: 676
      Points: 2,674
      Helping Hand
      Rank: Community Hero

      Here’s another option using regular expression

      Note the period matches any character. We could’ve escaped it to be a literal period as well

    • #272284
      Participant
      Topics: 2
      Replies: 1
      Points: 16
      Rank: Member

      Thanks, both of these examples worked for me.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.