Delete all unused ArecordData

Welcome Forums General PowerShell Q&A Delete all unused ArecordData

Viewing 2 reply threads
  • Author
    Posts
    • #184751
      Participant
      Topics: 1
      Replies: 1
      Points: -4
      Rank: Member

      Hello,

      I have a multiple "ARecordData" IP address (IPv4) which a identical and has to be removed via powerhshell command. Can some one help in the same ? I need a command that deletes all these unused ArecordData when a Server is terminated.

      Generally when a server is terminated in AWS EC2 instances, the ARecordData  still remains in the DNS. I want it to be auto deleted Рmay be ill create a ps1 file and put in execution under a Lambda function.

      I got the below code from your forum. Needs a bit more tweek.

      Remove-DnsServerResourceRecord -ComputerName "x.x.x.x" -ZoneName "example.com" -RRType A | select hostname,@{label='IP Address'; expression={$_.recorddata -contains '10.0.0.12'| select -expandproperty ipv4address}} | ft -AutoSize

      Here I want to delete all the IP's in ARecordData  which has "10.0.0.12"

      Please help

    • #184868
      Participant
      Topics: 1
      Replies: 1
      Points: -4
      Rank: Member

      Any luck people ?

    • #184907
      Moderator
      Topics: 0
      Replies: 42
      Points: 388
      Team MemberHelping Hand
      Rank: Contributor

      Well, that code seems quite destructive.

      You need to use `Get-DnsServerResourceRecord`, then filter records that match the IP you want to remove, then (hopefully) pipe it to `Remove-DnsServerResourceRecord`.

      It might look something like this:

      Get-DnsServerResourceRecord -ComputerName "x.x.x.x" -ZoneName "example.com" -RRType A | Where-Object {$_.RecordData -contains '10.0.0.12'} | Remove-DnsServerResourceRecord -WhatIf
      

      Your current snippet removes everything, and then (assuming Remove- does a passthru / displays all the records it removes) shows a table of IP addresses that were removed that match the IP you mention.

      I would recommend not running that on your existing environment.

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