2
2
title : Manage Azure CDN with PowerShell | Microsoft Docs
3
3
description : Use this tutorial to learn how to use PowerShell to manage aspects of your Azure Content Delivery Network endpoint profiles and endpoints.
4
4
services : cdn
5
- documentationcenter : ' '
6
5
author : duongau
7
6
manager : kumudd
8
- ms.assetid : fb6f57a5-6e26-4847-8fd9-b51fb05a79eb
9
7
ms.service : azure-cdn
10
- ms.workload : tbd
11
- ms.tgt_pltfrm : na
12
8
ms.topic : how-to
13
- ms.date : 02/27 /2023
9
+ ms.date : 04/24 /2023
14
10
ms.author : duau
15
11
ms.custom : devx-track-azurepowershell
16
-
17
12
---
18
13
19
14
# Manage Azure CDN with PowerShell
@@ -40,40 +35,33 @@ PS C:\> Get-Command -Module Az.Cdn
40
35
41
36
CommandType Name Version Source
42
37
----------- ---- ------- ------
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
77
65
```
78
66
79
67
## Getting help
@@ -99,12 +87,13 @@ DESCRIPTION
99
87
100
88
101
89
RELATED LINKS
90
+ https://docs.microsoft.com/powershell/module/az.cdn/get-azcdnprofile
102
91
103
92
REMARKS
104
93
To see the examples, type: "get-help Get-AzCdnProfile -examples".
105
94
For more information, type: "get-help Get-AzCdnProfile -detailed".
106
95
For technical information, type: "get-help Get-AzCdnProfile -full".
107
-
96
+ For online help, type: "get-help Get-AzCdnProfile -online"
108
97
```
109
98
110
99
## Listing existing Azure CDN profiles
@@ -119,9 +108,6 @@ This output can be piped to cmdlets for enumeration.
119
108
``` powershell
120
109
# Output the name of all profiles on this subscription.
121
110
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" }
125
111
```
126
112
127
113
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
133
119
> [ !TIP]
134
120
> 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.
135
121
>
136
- >
137
122
138
123
## Listing existing CDN endpoints
139
124
` 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
144
129
145
130
# Get all of the endpoints on a given profile.
146
131
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" }
153
132
```
154
133
155
134
## Creating CDN profiles and endpoints
@@ -163,26 +142,15 @@ Get-AzCdnProfile | Get-AzCdnEndpoint | Where-Object { $_.ResourceState -eq "Runn
163
142
164
143
``` powershell
165
144
# 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"
167
146
168
147
# 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
+ };
173
152
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
186
154
```
187
155
188
156
## Adding a custom domain
@@ -194,80 +162,91 @@ Else { Write-Host "No, that endpoint name is not available." }
194
162
>
195
163
196
164
``` 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
-
203
165
# 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
205
167
```
206
168
207
169
## Modifying an endpoint
208
- ` Set -AzCdnEndpoint` modifies an existing endpoint.
170
+ ` Update -AzCdnEndpoint` modifies an existing endpoint.
209
171
210
172
``` 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"
220
175
```
221
176
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.
224
179
225
180
``` powershell
226
181
# 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
228
186
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.
231
189
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")`
234
194
```
235
195
236
196
## Starting/Stopping CDN endpoints
237
197
` Start-AzCdnEndpoint ` and ` Stop-AzCdnEndpoint ` can be used to start and stop individual endpoints or groups of endpoints.
238
198
239
199
``` 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
245
202
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
248
205
```
249
206
250
207
## 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.
252
208
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 )
258
236
237
+ ``` powershell
259
238
# 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
263
242
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
266
247
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
271
250
```
272
251
273
252
## Deleting CDN resources
@@ -277,15 +256,13 @@ Set-AzCdnEndpoint -CdnEndpoint $ep
277
256
# Remove a single endpoint
278
257
Remove-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc
279
258
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
-
283
259
# Remove a single profile
284
260
Remove-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG
285
261
```
286
262
287
263
## Next Steps
288
- Learn how to automate Azure CDN with [ .NET] ( cdn-app-dev-net.md ) or [ Node.js] ( cdn-app-dev-node.md ) .
289
264
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 ) .
291
268
0 commit comments