Created
May 13, 2022 15:55
-
-
Save KianNH/1517012cac8db377dee7313618bebaee to your computer and use it in GitHub Desktop.
Cloudflare - Remove all DNS records in a given zone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$API_TOKEN = "<api-token>" | |
$ZONE_ID = "<zone-id>" | |
$baseUrl = "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" | |
$headers = @{ | |
'Authorization' = "Bearer $API_TOKEN" | |
'Content-Type' = "application/json" | |
} | |
$listUrl = $baseUrl + '?per_page=500' | |
$records = Invoke-RestMethod -Uri $listUrl -Method 'GET' -Headers $headers | |
$records = $records | Select-Object -ExpandProperty result | |
foreach ($record in $records) { | |
Write-Host "Deleting $($record.name) that points to $($record.content)" | |
$deleteUrl = $baseUrl + '/' + $record.id | |
Invoke-RestMethod -Uri $deleteUrl -Method 'DELETE' -Headers $headers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obvious note - this will indiscriminately delete all the records it can find in a zone.