CloudFlare API and PowerShell

CloudFlare has a nicely documented and approachable API for automating all aspects of their growing range of DNS, security and protection features.

The API lives here:

My interest was around quickly getting PowerShell to pull existing external DNS records and bring them into CloudFlare (and create a zone)

The final script was simple. Only really three parameters to change depending on domain name and your CloudFlare authentication email and API key.

Additionally, the jump_start=$true parameter tells the API to fetch existing DNS records it finds and add them to the new zone created on CloudFlare.

$domainname = ""
$auth_email = ""
$auth_key = "my-cloudflare-api-key"

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Auth-Email", $auth_email)
$headers.Add("X-Auth-Key", $auth_key)

$data = @{

$uri = ""

$json =$data | ConvertTo-Json

Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $json -ContentType 'application/json'