question

joaomanoelc avatar image
0 Votes"
joaomanoelc asked joaomanoelc commented

Remove multiple A records from file txt with hostnames

from a txt file with the hostname names I would like to delete all type a records in DNS
get-content -path c:\temp\ListHost.txt

windows-server-powershell
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What about the associated PTR records (assuming you have a reverse lookup zone for the IP addresses)?

Are there any CNAME records (or any other record types) that are refer to the A record(s)?

0 Votes 0 ·

The same records are in the reverse zone and I want to delete them

0 Votes 0 ·
AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered joaomanoelc commented

Hi @joaomanoelc ,

please try this (the -force needs to be inside the {}):

 Get-Content -path c:\temp\ListHost.txt | ForEach {Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "A" -Name "$" -Force}

To remove the PTR record the -RRType needs to be Ptr.
Maybe this helps:
https://rcmtech.wordpress.com/2014/02/26/get-and-delete-dns-a-and-ptr-records-via-powershell/


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Andreas, thank you very much the command was successfully executed.
I will need to delete the PTR records I will analyze the link you provided here and if I can't I will record another question.
I will mark as an answer

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered joaomanoelc commented

Hi @joaomanoelc ,

maybe this helps to get started (not tested by myself!):

 Get-Content -path c:\temp\ListHost.txt | ForEach {Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "A" -Name "$_"}

You have to modify the ZoneName for you needs.


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.



your command works for remove and list, but by putting -Confirm:$false or -force the powershell informs you that the parameter is not supported.

I have a list of 100 records that I need to delete and it would be nice not to have to confirm the deletion of each record.

Get-Content -path c:\temp\ListHost.txt | ForEach {Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "A" -Name "$"} -force
Get-Content -path c:\temp\ListHost.txt | ForEach {Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "A" -Name "$
"} -Confirm:$false

0 Votes 0 ·