Skip to content

Instantly share code, notes, and snippets.

@kimboslice99
Last active December 1, 2022 03:07
Show Gist options
  • Save kimboslice99/35905e2b286d3af0039a5c2784fa1be0 to your computer and use it in GitHub Desktop.
Save kimboslice99/35905e2b286d3af0039a5c2784fa1be0 to your computer and use it in GitHub Desktop.
Update Cloudflare _mta-sts record
$email = 'CLOUDFLARE_EMAIL'
$apikey = 'CLOUDLFARE_APIKEY'
$ZoneID = 'ZONEID'
$type = 'TXT'
$Record = '_mta-sts.domain.com'
$timestamp = Get-Date -Format "yyyyMMddThhmmss"
Try { $result = Invoke-RestMethod -Uri "https://api.cloudflare.com/client/v4/zones/$ZoneID/dns_records?type=$type&name=$Record&page=1&per_page=100&order=type&direction=desc&match=all" -Method 'GET' -ContentType "application/json" -Headers @{'Accept'='application/json';'X-Auth-Email'="$email";'X-Auth-Key'="$apikey"} |
% {$_.result} }
Catch {Write-Host "Cannot contact CF for record info"
Exit }
$RecordID = ($result).id
$contents = "v=STSv1; id=$timestamp;"
IWR -Uri "https://api.cloudflare.com/client/v4/zones/$ZoneID/dns_records/$RecordID" -Method 'PUT' -Body "{`"type`":`"$type`",`"name`":`"$Record`",`"content`":`"$contents`",`"ttl`":`"1`",`"proxied`":false}" -ContentType "application/json" -Headers @{'Accept'='application/json';'X-Auth-Email'="$email";'X-Auth-Key'="$apikey"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment