Skip to content

Instantly share code, notes, and snippets.

@vkhazin
Last active March 26, 2021 12:15
Show Gist options
  • Save vkhazin/a231f0c30c9937727ee9fbbb1c9c951b to your computer and use it in GitHub Desktop.
Save vkhazin/a231f0c30c9937727ee9fbbb1c9c951b to your computer and use it in GitHub Desktop.
Azure DevOps purge CDN End-Point
# https://docs.microsoft.com/en-us/powershell/azure/authenticate-azureps?view=azps-5.6.0#password-based-authentication
# https://docs.microsoft.com/en-us/azure/cdn/cdn-manage-powershell#purgingpre-loading-cdn-assets
param (
[string]$applicationId,
[string]$tenantId,
[string]$accessKey,
[string]$resourceGroupName,
[string]$profileName,
[string]$endpointName,
# Must be surrounded by double-quotes and no wildcard, e.g: "/myfolder/"
[string]$targetFolder
)
# Install Modules missing on Azure hosted agents
Install-Module Az.Accounts -Scope CurrentUser -Force
Install-Module Az.Cdn -Scope CurrentUser -Force
# Authenticate as service principal
$secureAccessKey = ConvertTo-SecureString $accessKey -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($applicationId, $secureAccessKey)
Connect-AzAccount -ServicePrincipal -Credential $credentials -Tenant $tenantId
# List profiles
# Get-AzCdnProfile
# List end-points
# Get-AzCdnEndpoint -ProfileName $profileName -ResourceGroupName $resourceGroupName
# Purge CDN ~10 minutes
Unpublish-AzCdnEndpointContent `
-ProfileName $profileName `
-ResourceGroupName $resourceGroupName `
-EndpointName $endpointName `
-PurgeContent "/$targetFolder/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment