Azure CDN PowerShell Reference

This section provides reference documentation for the Azure CDN PowerShell module, enabling you to manage your Azure Content Delivery Network resources using PowerShell.

Overview of Azure CDN PowerShell Module

The Azure CDN PowerShell module allows you to automate the deployment and management of Azure CDN profiles, endpoints, and origins. You can perform tasks such as creating, configuring, and deleting CDN resources, managing custom domains, and retrieving performance metrics.

To get started, ensure you have the Az PowerShell module installed and connected to your Azure subscription.

Az.Cdn Module Cmdlets

Below is a list of commonly used cmdlets available in the Az.Cdn module.

Profile Management

Endpoint Management

Origin Management

Custom Domain Management

Rule Set Management

Example Usage

Creating a CDN Profile and Endpoint

# Requires Az.Cdn module
# Connect to your Azure account
Connect-AzAccount

# Set context to your subscription
Set-AzContext -SubscriptionId "YOUR_SUBSCRIPTION_ID"

# Define variables
$resourceGroupName = "MyResourceGroup"
$profileName = "mycdnprofile"
$endpointName = "mycdnendpoint"
$location = "westus"
$sku = "Standard_Microsoft" # Or Premium_Verizon, Standard_Akamai etc.

# Create a resource group if it doesn't exist
If (-not (Get-AzResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue)) {
    New-AzResourceGroup -Name $resourceGroupName -Location $location
}

# Create a CDN profile
New-AzCdnProfile -Name $profileName -ResourceGroupName $resourceGroupName -Location $location -Sku $sku

# Get the created profile object
$cdnProfile = Get-AzCdnProfile -Name $profileName -ResourceGroupName $resourceGroupName

# Create a CDN endpoint
New-AzCdnEndpoint -Name $endpointName -Profile $cdnProfile -OriginHostHeader "yourorigin.blob.core.windows.net" -HostName "yourorigin.blob.core.windows.net" -Location $location

# Display endpoint details
Get-AzCdnEndpoint -Name $endpointName -ProfileName $profileName -ResourceGroupName $resourceGroupName | Format-List
            

Purging Content from an Endpoint

# Define variables
$resourceGroupName = "MyResourceGroup"
$profileName = "mycdnprofile"
$endpointName = "mycdnendpoint"
$contentPaths = @("/images/logo.png", "/css/*") # Paths to purge

# Purge content
Purge-AzCdnEndpoint -Name $endpointName -ProfileName $profileName -ResourceGroupName $resourceGroupName -ContentPath $contentPaths -PurgeRecursive

# Note: PurgeRecursive parameter is specific to certain CDN providers.
            

Further Resources