Remove multiple A records from file txt with hostnames

joaomanoelc 171 Reputation points
2021-06-14T19:15:45.447+00:00

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
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 109.1K Reputation points MVP
    2021-06-14T20:37:35.333+00:00

    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

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 109.1K Reputation points MVP
    2021-06-14T19:27:46.627+00:00

    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 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.