Branch | Windows - PowerShell | Windows - pwsh | Linux | MacOS |
---|---|---|---|---|
main | ||||
dev |
PowerShell module for the Cloudflare Client API v4. See similar projects python-cloudflare and cloudflare-go as well as Cloudflare products
pwshCloudflare will be published to PSGallery in the future. For now clone this repo and import the module.
git clone https://github.com/connorcarnes/pwshCloudflare
Import-Module '.pwshCloudflare/src/pwshCloudflare/pwshCloudflare.psd1'
Set-CloudflareSession
creates a [Microsoft.PowerShell.Commands.WebRequestSession]
object with the appropriate headers, saves it to $Script:cfSession
, and uses it make subsequent API calls. By default Set-CloudflareSession
only configures authentication for the current session. Use the -SaveToFile
and -LoadOnImport
parameters to save your configuration and have it load on module import. Your credentials will be stored in plaintext. Examples are included in the Quickstart section below.
You can use API token authentication, API key authentication, or both. See Get Started - Cloudflare Fundamentals for details. Set-CloudflareSession
will validate the provided credentials with Test-CloudflareSession
.
$Splat = @{
Email = "user@example.com"
ApiKey = "API_KEY"
ApiToken = "API_TOKEN"
}
Set-CloudflareSession @Splat
# Your credentials will be stored in plaintext. Default config file location:
# $Folder = [Environment]::GetFolderPath([Environment+SpecialFolder]::UserProfile)
# $FilePath = "$Folder\.pwshCloudflare\config.xml"
$Splat = @{
Email = "user@example.com"
ApiKey = "API_KEY"
ApiToken = "API_TOKEN"
SaveToFile = $true
LoadOnImport = $true
}
Set-CloudflareSession @Splat
Get-CfZone
Get-CFZoneRecord -ZoneName 'example.com'
$ZoneName = 'example.com'
$Zone = Get-CfZone | Where-Object {$_.Name -eq $ZoneName}
Get-CFZoneRecord -ZoneId $Zone.id