Delete all unused ArecordData

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

Any luck people ?

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.