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
-
New-AzCdnProfile
Creates a new Azure CDN profile.
-
Get-AzCdnProfile
Retrieves existing Azure CDN profiles.
-
Remove-AzCdnProfile
Deletes an Azure CDN profile.
-
Set-AzCdnProfile
Updates properties of an Azure CDN profile.
Endpoint Management
-
New-AzCdnEndpoint
Creates a new CDN endpoint within a profile.
-
Get-AzCdnEndpoint
Retrieves existing CDN endpoints.
-
Remove-AzCdnEndpoint
Deletes a CDN endpoint.
-
Set-AzCdnEndpoint
Updates properties of a CDN endpoint.
-
Start-AzCdnEndpoint
Starts a disabled CDN endpoint.
-
Stop-AzCdnEndpoint
Stops a running CDN endpoint.
-
Resume-AzCdnEndpoint
Resumes a paused CDN endpoint.
-
Purge-AzCdnEndpoint
Purges content from a CDN endpoint.
Origin Management
-
New-AzCdnOrigin
Adds a new origin to a CDN endpoint.
-
Get-AzCdnOrigin
Retrieves CDN origins for an endpoint.
-
Remove-AzCdnOrigin
Removes an origin from a CDN endpoint.
-
Set-AzCdnOrigin
Updates properties of a CDN origin.
Custom Domain Management
-
New-AzCdnCustomDomain
Adds a custom domain to a CDN endpoint.
-
Get-AzCdnCustomDomain
Retrieves custom domains for a CDN endpoint.
-
Remove-AzCdnCustomDomain
Removes a custom domain from a CDN endpoint.
Rule Set Management
-
New-AzCdnRuleSet
Creates a new rule set for managing cache behavior.
-
Get-AzCdnRuleSet
Retrieves existing rule sets.
-
Remove-AzCdnRuleSet
Deletes a rule set.
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.