Skip to content

Commit c3f4b2e

Browse files
Merge pull request #235655 from duongau/pscdn
Azure CDN - Manage CDN with PowerShell - update and refresh doc
2 parents 615cc6e + e13fe96 commit c3f4b2e

File tree

1 file changed

+96
-119
lines changed

1 file changed

+96
-119
lines changed

articles/cdn/cdn-manage-powershell.md

Lines changed: 96 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
title: Manage Azure CDN with PowerShell | Microsoft Docs
33
description: Use this tutorial to learn how to use PowerShell to manage aspects of your Azure Content Delivery Network endpoint profiles and endpoints.
44
services: cdn
5-
documentationcenter: ''
65
author: duongau
76
manager: kumudd
8-
ms.assetid: fb6f57a5-6e26-4847-8fd9-b51fb05a79eb
97
ms.service: azure-cdn
10-
ms.workload: tbd
11-
ms.tgt_pltfrm: na
128
ms.topic: how-to
13-
ms.date: 02/27/2023
9+
ms.date: 04/24/2023
1410
ms.author: duau
1511
ms.custom: devx-track-azurepowershell
16-
1712
---
1813

1914
# Manage Azure CDN with PowerShell
@@ -40,40 +35,33 @@ PS C:\> Get-Command -Module Az.Cdn
4035
4136
CommandType Name Version Source
4237
----------- ---- ------- ------
43-
Cmdlet Confirm-AzCdnEndpointProbeURL 1.4.0 Az.Cdn
44-
Cmdlet Disable-AzCdnCustomDomain 1.4.0 Az.Cdn
45-
Cmdlet Disable-AzCdnCustomDomainHttps 1.4.0 Az.Cdn
46-
Cmdlet Enable-AzCdnCustomDomain 1.4.0 Az.Cdn
47-
Cmdlet Enable-AzCdnCustomDomainHttps 1.4.0 Az.Cdn
48-
Cmdlet Get-AzCdnCustomDomain 1.4.0 Az.Cdn
49-
Cmdlet Get-AzCdnEdgeNode 1.4.0 Az.Cdn
50-
Cmdlet Get-AzCdnEndpoint 1.4.0 Az.Cdn
51-
Cmdlet Get-AzCdnEndpointNameAvailability 1.4.0 Az.Cdn
52-
Cmdlet Get-AzCdnEndpointResourceUsage 1.4.0 Az.Cdn
53-
Cmdlet Get-AzCdnOrigin 1.4.0 Az.Cdn
54-
Cmdlet Get-AzCdnProfile 1.4.0 Az.Cdn
55-
Cmdlet Get-AzCdnProfileResourceUsage 1.4.0 Az.Cdn
56-
Cmdlet Get-AzCdnProfileSsoUrl 1.4.0 Az.Cdn
57-
Cmdlet Get-AzCdnProfileSupportedOptimizationType 1.4.0 Az.Cdn
58-
Cmdlet Get-AzCdnSubscriptionResourceUsage 1.4.0 Az.Cdn
59-
Cmdlet New-AzCdnCustomDomain 1.4.0 Az.Cdn
60-
Cmdlet New-AzCdnDeliveryPolicy 1.4.0 Az.Cdn
61-
Cmdlet New-AzCdnDeliveryRule 1.4.0 Az.Cdn
62-
Cmdlet New-AzCdnDeliveryRuleAction 1.4.0 Az.Cdn
63-
Cmdlet New-AzCdnDeliveryRuleCondition 1.4.0 Az.Cdn
64-
Cmdlet New-AzCdnEndpoint 1.4.0 Az.Cdn
65-
Cmdlet New-AzCdnProfile 1.4.0 Az.Cdn
66-
Cmdlet Publish-AzCdnEndpointContent 1.4.0 Az.Cdn
67-
Cmdlet Remove-AzCdnCustomDomain 1.4.0 Az.Cdn
68-
Cmdlet Remove-AzCdnEndpoint 1.4.0 Az.Cdn
69-
Cmdlet Remove-AzCdnProfile 1.4.0 Az.Cdn
70-
Cmdlet Set-AzCdnEndpoint 1.4.0 Az.Cdn
71-
Cmdlet Set-AzCdnOrigin 1.4.0 Az.Cdn
72-
Cmdlet Set-AzCdnProfile 1.4.0 Az.Cdn
73-
Cmdlet Start-AzCdnEndpoint 1.4.0 Az.Cdn
74-
Cmdlet Stop-AzCdnEndpoint 1.4.0 Az.Cdn
75-
Cmdlet Test-AzCdnCustomDomain 1.4.0 Az.Cdn
76-
Cmdlet Unpublish-AzCdnEndpointContent 1.4.0 Az.Cdn
38+
Cmdlet Confirm-AzCdnEndpointProbeURL 2.1.0 Az.Cdn
39+
Cmdlet Disable-AzCdnCustomDomain 2.1.0 Az.Cdn
40+
Cmdlet Disable-AzCdnCustomDomainHttps 2.1.0 Az.Cdn
41+
Cmdlet Enable-AzCdnCustomDomain 2.1.0 Az.Cdn
42+
Cmdlet Enable-AzCdnCustomDomainHttps 2.1.0 Az.Cdn
43+
Cmdlet Get-AzCdnCustomDomain 2.1.0 Az.Cdn
44+
Cmdlet Get-AzCdnEdgeNode 2.1.0 Az.Cdn
45+
Cmdlet Get-AzCdnEndpoint 2.1.0 Az.Cdn
46+
Cmdlet Get-AzCdnEndpointResourceUsage 2.1.0 Az.Cdn
47+
Cmdlet Get-AzCdnOrigin 2.1.0 Az.Cdn
48+
Cmdlet Get-AzCdnProfile 2.1.0 Az.Cdn
49+
Cmdlet Get-AzCdnProfileResourceUsage 2.1.0 Az.Cdn
50+
Cmdlet Get-AzCdnProfileSupportedOptimizationType 2.1.0 Az.Cdn
51+
Cmdlet Get-AzCdnSubscriptionResourceUsage 2.1.0 Az.Cdn
52+
Cmdlet New-AzCdnCustomDomain 2.1.0 Az.Cdn
53+
Cmdlet New-AzCdnDeliveryPolicy 2.1.0 Az.Cdn
54+
Cmdlet New-AzCdnDeliveryRule 2.1.0 Az.Cdn
55+
Cmdlet New-AzCdnDeliveryRuleAction 2.1.0 Az.Cdn
56+
Cmdlet New-AzCdnDeliveryRuleCondition 2.1.0 Az.Cdn
57+
Cmdlet New-AzCdnEndpoint 2.1.0 Az.Cdn
58+
Cmdlet New-AzCdnProfile 2.1.0 Az.Cdn
59+
Cmdlet Remove-AzCdnCustomDomain 2.1.0 Az.Cdn
60+
Cmdlet Remove-AzCdnEndpoint 2.1.0 Az.Cdn
61+
Cmdlet Remove-AzCdnProfile 2.1.0 Az.Cdn
62+
Cmdlet Set-AzCdnProfile 2.1.0 Az.Cdn
63+
Cmdlet Start-AzCdnEndpoint 2.1.0 Az.Cdn
64+
Cmdlet Stop-AzCdnEndpoint 2.1.0 Az.Cdn
7765
```
7866

7967
## Getting help
@@ -99,12 +87,13 @@ DESCRIPTION
9987
10088
10189
RELATED LINKS
90+
https://docs.microsoft.com/powershell/module/az.cdn/get-azcdnprofile
10291
10392
REMARKS
10493
To see the examples, type: "get-help Get-AzCdnProfile -examples".
10594
For more information, type: "get-help Get-AzCdnProfile -detailed".
10695
For technical information, type: "get-help Get-AzCdnProfile -full".
107-
96+
For online help, type: "get-help Get-AzCdnProfile -online"
10897
```
10998

11099
## Listing existing Azure CDN profiles
@@ -119,9 +108,6 @@ This output can be piped to cmdlets for enumeration.
119108
```powershell
120109
# Output the name of all profiles on this subscription.
121110
Get-AzCdnProfile | ForEach-Object { Write-Host $_.Name }
122-
123-
# Return only **Azure CDN from Verizon** profiles.
124-
Get-AzCdnProfile | Where-Object { $_.Sku.Name -eq "Standard_Verizon" }
125111
```
126112

127113
You can also return a single profile by specifying the profile name and resource group.
@@ -133,7 +119,6 @@ Get-AzCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG
133119
> [!TIP]
134120
> It is possible to have multiple CDN profiles with the same name, so long as they are in different resource groups. Omitting the `ResourceGroupName` parameter returns all profiles with a matching name.
135121
>
136-
>
137122
138123
## Listing existing CDN endpoints
139124
`Get-AzCdnEndpoint` can retrieve an individual endpoint or all the endpoints on a profile.
@@ -144,12 +129,6 @@ Get-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointNam
144129
145130
# Get all of the endpoints on a given profile.
146131
Get-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG
147-
148-
# Return all of the endpoints on all of the profiles.
149-
Get-AzCdnProfile | Get-AzCdnEndpoint
150-
151-
# Return all of the endpoints in this subscription that are currently running.
152-
Get-AzCdnProfile | Get-AzCdnEndpoint | Where-Object { $_.ResourceState -eq "Running" }
153132
```
154133

155134
## Creating CDN profiles and endpoints
@@ -163,26 +142,15 @@ Get-AzCdnProfile | Get-AzCdnEndpoint | Where-Object { $_.ResourceState -eq "Runn
163142

164143
```powershell
165144
# Create a new profile
166-
New-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku Standard_Akamai -Location "Central US"
145+
New-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku Standard_Microsoft -Location "Central US"
167146
168147
# Create a new endpoint
169-
New-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Location "Central US" -EndpointName cdnposhdoc -OriginName "Contoso" -OriginHostName "www.contoso.com"
170-
171-
# Create a new profile and endpoint (same as above) in one line
172-
New-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku Standard_Akamai -Location "Central US" | New-AzCdnEndpoint -EndpointName cdnposhdoc -OriginName "Contoso" -OriginHostName "www.contoso.com"
148+
$origin = @{
149+
Name = "Contoso"
150+
HostName = "www.contoso.com"
151+
};
173152
174-
```
175-
176-
## Checking endpoint name availability
177-
`Get-AzCdnEndpointNameAvailability` returns an object indicating if an endpoint name is available.
178-
179-
```powershell
180-
# Retrieve availability
181-
$availability = Get-AzCdnEndpointNameAvailability -EndpointName "cdnposhdoc"
182-
183-
# If available, write a message to the console.
184-
If($availability.NameAvailable) { Write-Host "Yes, that endpoint name is available." }
185-
Else { Write-Host "No, that endpoint name is not available." }
153+
New-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Location "Central US" -EndpointName cdnposhdoc -Origin $origin
186154
```
187155

188156
## Adding a custom domain
@@ -194,80 +162,91 @@ Else { Write-Host "No, that endpoint name is not available." }
194162
>
195163
196164
```powershell
197-
# Get an existing endpoint
198-
$endpoint = Get-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc
199-
200-
# Check the mapping
201-
$result = Test-AzCdnCustomDomain -CdnEndpoint $endpoint -CustomDomainHostName "cdn.contoso.com"
202-
203165
# Create the custom domain on the endpoint
204-
If($result.CustomDomainValidated){ New-AzCdnCustomDomain -CustomDomainName Contoso -HostName "cdn.contoso.com" -CdnEndpoint $endpoint }
166+
New-AzCdnCustomDomain -ResourceGroupName CdnDemoRG -ProfileName CdnPoshDemo -Name contoso -HostName "cdn.contoso.com" -EndpointName cdnposhdoc
205167
```
206168

207169
## Modifying an endpoint
208-
`Set-AzCdnEndpoint` modifies an existing endpoint.
170+
`Update-AzCdnEndpoint` modifies an existing endpoint.
209171

210172
```powershell
211-
# Get an existing endpoint
212-
$endpoint = Get-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc
213-
214-
# Set up content compression
215-
$endpoint.IsCompressionEnabled = $true
216-
$endpoint.ContentTypesToCompress = "text/javascript","text/css","application/json"
217-
218-
# Save the changed endpoint and apply the changes
219-
Set-AzCdnEndpoint -CdnEndpoint $endpoint
173+
# Update endpoint with compression settings
174+
Update-AzCdnEndpoint -Name cdnposhdoc -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -IsCompressionEnabled -ContentTypesToCompress "text/javascript","text/css","application/json"
220175
```
221176

222-
## Purging/Pre-loading CDN assets
223-
`Unpublish-AzCdnEndpointContent` purges cached assets, while `Publish-AzCdnEndpointContent` pre-loads assets on supported endpoints.
177+
## Purging
178+
`Clear-AzCdnEndpointContent` purges cached assets.
224179

225180
```powershell
226181
# Purge some assets.
227-
Unpublish-AzCdnEndpointContent -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo -PurgeContent "/images/kitten.png","/video/rickroll.mp4"
182+
Clear-AzCdnEndpointContent -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc -ContentFilePath @("/images/kitten.png","/video/rickroll.mp4")
183+
```
184+
185+
## Pre-load some assets
228186

229-
# Pre-load some assets.
230-
Publish-AzCdnEndpointContent -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo -LoadContent "/images/kitten.png","/video/rickroll.mp4"
187+
> [!NOTE]
188+
> Pre-loading is only available on Azure CDN from Verizon profiles.
231189
232-
# Purge everything in /images/ on all endpoints.
233-
Get-AzCdnProfile | Get-AzCdnEndpoint | Unpublish-AzCdnEndpointContent -PurgeContent "/images/*"
190+
`Import-AzCdnEndpointContent` pre-loads assets into the CDN cache.
191+
192+
```powershell
193+
Import-AzCdnEndpointContent -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc -ContentFilePath @("/images/kitten.png","/video/rickroll.mp4")`
234194
```
235195

236196
## Starting/Stopping CDN endpoints
237197
`Start-AzCdnEndpoint` and `Stop-AzCdnEndpoint` can be used to start and stop individual endpoints or groups of endpoints.
238198

239199
```powershell
240-
# Stop the cdndocdemo endpoint
241-
Stop-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo
242-
243-
# Stop all endpoints
244-
Get-AzCdnProfile | Get-AzCdnEndpoint | Stop-AzCdnEndpoint
200+
# Stop the CdnPoshDemo endpoint
201+
Stop-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Name cdnposhdoc
245202
246-
# Start all endpoints
247-
Get-AzCdnProfile | Get-AzCdnEndpoint | Start-AzCdnEndpoint
203+
# Start the CdnPoshDemo endpoint
204+
Start-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Name cdnposhdoc
248205
```
249206

250207
## Creating Standard Rules engine policy and applying to an existing CDN endpoint
251-
`New-AzCdnDeliveryRule`, `New=AzCdnDeliveryRuleCondition`, and `New-AzCdnDeliveryRuleAction` can be used to configure the Azure CDN Standard Rules engine on Azure CDN from Microsoft profiles.
252208

253-
```powershell
254-
# Create a new http to https redirect rule
255-
$Condition=New-AzCdnDeliveryRuleCondition -MatchVariable RequestProtocol -Operator Equal -MatchValue HTTP
256-
$Action=New-AzCdnDeliveryRuleAction -RedirectType Found -DestinationProtocol HTTPS
257-
$HttpToHttpsRedirectRule=New-AzCdnDeliveryRule -Name "HttpToHttpsRedirectRule" -Order 2 -Condition $Condition -Action $Action
209+
The following list of cmdlets can be used to create a Standard Rules engine policy and apply it to an existing CDN endpoint.
210+
211+
Conditions:
212+
213+
* [New-AzFrontDoorCdnRuleCookiesConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulecookiesconditionobject)
214+
* [New-AzCdnDeliveryRuleHttpVersionConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulehttpversionconditionobject)
215+
* [New-AzCdnDeliveryRuleIsDeviceConditionObject](/powershell/module/az.cdn/new-azcdndeliveryruleisdeviceconditionobject)
216+
* [New-AzCdnDeliveryRulePostArgsConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulepostargsconditionobject)
217+
* [New-AzCdnDeliveryRuleQueryStringConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulequerystringconditionobject)
218+
* [New-AzCdnDeliveryRuleRemoteAddressConditionObject](/powershell/module/az.cdn/new-azcdndeliveryruleremoteaddressconditionobject)
219+
* [New-AzCdnDeliveryRuleRequestBodyConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequestbodyconditionobject)
220+
* [New-AzCdnDeliveryRuleRequestHeaderConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequestheaderconditionobject)
221+
* [New-AzCdnDeliveryRuleRequestMethodConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequestmethodconditionobject)
222+
* [New-AzCdnDeliveryRuleRequestSchemeConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequestschemeconditionobject)
223+
* [New-AzCdnDeliveryRuleRequestUriConditionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequesturiconditionobject)
224+
* [New-AzCdnDeliveryRuleResponseHeaderActionObject](/powershell/module/az.cdn/new-azcdndeliveryruleresponseheaderactionobject)
225+
* [New-AzCdnDeliveryRuleUrlFileExtensionConditionObject](/powershell/module/az.cdn/new-azcdndeliveryruleurlfileextensionconditionobject)
226+
* [New-AzCdnDeliveryRuleUrlFileNameConditionObject](/powershell/module/az.cdn/new-azcdndeliveryruleurlfilenameconditionobject)
227+
* [New-AzCdnDeliveryRuleUrlPathConditionObject](/powershell/module/az.cdn/new-azcdndeliveryruleurlpathconditionobject)
228+
229+
Actions:
230+
231+
* [New-AzCdnDeliveryRuleRequestHeaderActionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequestheaderactionobject)
232+
* [New-AzCdnDeliveryRuleRequestHeaderActionObject](/powershell/module/az.cdn/new-azcdndeliveryrulerequestheaderactionobject)
233+
* [New-AzCdnUrlRedirectActionObject](/powershell/module/az.cdn/new-azcdnurlredirectactionobject)
234+
* [New-AzCdnUrlRewriteActionObject](/powershell/module/az.cdn/new-azcdnurlrewriteactionobject)
235+
* [New-AzCdnUrlSigningActionObject](/powershell/module/az.cdn/new-azcdnurlsigningactionobject)
258236

237+
```powershell
259238
# Create a path based Response header modification rule.
260-
$Cond1=New-AzCdnDeliveryRuleCondition -MatchVariable UrlPath -Operator BeginsWith -MatchValue "/images/"
261-
$Action1=New-AzCdnDeliveryRuleAction -HeaderActionType ModifyResponseHeader -Action Overwrite -HeaderName "Access-Control-Allow-Origin" -Value "*"
262-
$PathBasedCacheOverrideRule=New-AzCdnDeliveryRule -Name "PathBasedCacheOverride" -Order 1 -Condition $Cond1 -Action $action1
239+
$cond1 = New-AzCdnDeliveryRuleUrlPathConditionObject -Name UrlPath -ParameterOperator BeginsWith -ParameterMatchValue "/images/"
240+
$action1 = New-AzCdnDeliveryRuleResponseHeaderActionObject -Name ModifyResponseHeader -ParameterHeaderAction Overwrite -ParameterHeaderName "Access-Control-Allow-Origin" -ParameterValue "*"
241+
$rule1 = New-AzCdnDeliveryRuleObject -Name "PathBasedCacheOverride" -Order 1 -Condition $cond1 -Action $action1
263242
264-
# Create a delivery policy with above deliveryRules.
265-
$Policy = New-AzCdnDeliveryPolicy -Description "DeliveryPolicy" -Rule $HttpToHttpsRedirectRule,$UrlRewriteRule
243+
# Create a new http to https redirect rule
244+
$cond1 = New-AzCdnDeliveryRuleRequestSchemeConditionObject -Name RequestScheme -ParameterMatchValue HTTPS
245+
$action1 = New-AzCdnUrlRedirectActionObject -Name UrlRedirect -ParameterRedirectType Found -ParameterDestinationProtocol Https
246+
$rule2 = New-AzCdnDeliveryRuleObject -Name "UrlRewriteRule" -Order 2 -Condition $cond1 -Action $action1
266247
267-
# Update existing endpoint with created delivery policy
268-
$ep = Get-AzCdnEndpoint -EndpointName cdndocdemo -ProfileName CdnDemo -ResourceGroupName CdnDemoRG
269-
$ep.DeliveryPolicy = $Policy
270-
Set-AzCdnEndpoint -CdnEndpoint $ep
248+
# Update existing endpoint with new rules
249+
Update-AzCdnEndpoint -Name cdnposhdoc -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -DeliveryPolicyRule $rule1,$rule2
271250
```
272251

273252
## Deleting CDN resources
@@ -277,15 +256,13 @@ Set-AzCdnEndpoint -CdnEndpoint $ep
277256
# Remove a single endpoint
278257
Remove-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc
279258
280-
# Remove all the endpoints on a profile and skip confirmation (-Force)
281-
Get-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG | Get-AzCdnEndpoint | Remove-AzCdnEndpoint -Force
282-
283259
# Remove a single profile
284260
Remove-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG
285261
```
286262

287263
## Next Steps
288-
Learn how to automate Azure CDN with [.NET](cdn-app-dev-net.md) or [Node.js](cdn-app-dev-node.md).
289264

290-
To learn about CDN features, see [CDN Overview](cdn-overview.md).
265+
* Learn how to automate Azure CDN with [.NET](cdn-app-dev-net.md) or [Node.js](cdn-app-dev-node.md).
266+
267+
* To learn about CDN features, see [CDN Overview](cdn-overview.md).
291268

0 commit comments

Comments
 (0)