Skip to content

Instantly share code, notes, and snippets.

@mardahl
Last active April 10, 2024 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mardahl/4d6e71a2b41a962e53896902066b7893 to your computer and use it in GitHub Desktop.
Save mardahl/4d6e71a2b41a962e53896902066b7893 to your computer and use it in GitHub Desktop.
CloudFlare powershell to bulk add new DNS Zones
#region declarations
$apikey = 'axxxxxxxxxxxxxxxxx6a4f5bxxxxxxxxxxxxx'
$email = 'xxxxxxxxx@xxxxxxxxx.xxx'
$accountid = 'b6xxxxxxxxxxxxxxxxx8e57xxxx'
$domains = $(Get-Content .\domains.txt) #text file with 1 domain per line
#endregion declarations
#region execute
foreach ($domain in $domains){
$headers = @{
'X-Auth-Key' = $apikey
'X-Auth-Email' = $email
}
$settings = @{
"name" = $domain.ToString()
"account" = $(
@{
"id" = $accountid
}
)
"jump_start" = $false
"type" = "full"
}
$body = ConvertTo-Json -InputObject $settings
Write-Verbose "Adding $domain..." -Verbose
$createResponse = Invoke-RestMethod -Uri "https://api.cloudflare.com/client/v4/zones" -Method POST -Headers $headers -Body $body -ContentType "application/json"
$zoneID = $createResponse.result.id.ToString()
#scan for DNS records on current name server - comment the next line to disable this feature. This is a fix for the jump_start parameter not working.
$scanResponse = Invoke-RestMethod -Uri "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/scan" -Method POST -Headers $headers
Write-Verbose "Finished $domain" -Verbose
}
#endregion execute
@mardahl
Copy link
Author

mardahl commented Oct 7, 2021

fixed cloudflare jump_start not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment