Skip to content

Instantly share code, notes, and snippets.

Last active January 24, 2019 21:27
What would you like to do?
Simple PowerShell function to retrieve Cloudflare Zones on an account
Quick PowerShell function to obtain your CloudFlare Zones using the v4 API
This function is to obtain a list of zones on your CloudFlare account
You can then use the returned id for other CloudFlare API calls.
Obtain your API token here:
This is typically the e-mail you login to the CloudFlare Dashboard with.
C:\Temp> Get-CFZones -Token your-api-key -E-Mail your@email.address
Author: Sterling Hammer @CDLHamma -
function Get-CFZones {
param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
$APIURI = ''
#Build required header for authentication
$Headers = @{
'X-Auth-Key' = $Token
'X-Auth-Email' = $EMail
$Zones = Invoke-RestMethod -Headers $Headers -Uri $APIURI/zones
$ZoneOutput = @()
foreach ($zone in $Zones.result) {
$ZoneOutput += [PSCustomObject]@{
"Id" = $
"Name" = $
"Status" = $Zone.status
"Paused" = $Zone.paused
"Name Servers" = $Zone.name_servers
Write-Output $ZoneOutput
$APIToken = "your-api-key"
$AccountEmail = "your@e-mail.address"
#Grab a list of CloudFlare Zones on your account
Get-CFZones -Token $APIToken -EMail $AccountEmail
#Grab a specific Zone ID - this will be used in other CloudFlare API Calls
(Get-CFZones -Token $APIToken -EMail $AccountEmail |where Name -eq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment