Important
- 從 2025 年 8 月 15 日起,來自 Microsoft (傳統) 的 Azure CDN 將不再支援新的網域上線或配置檔建立。 遷移至 AFD 標準和進階 ,以建立新的網域或配置檔,並避免服務中斷。 瞭解更多資訊
- 從 2025 年 8 月 15 日起,來自 Microsoft (傳統) 的 Azure CDN 將不再支援受控憑證。 若要避免服務中斷,請 切換至 [攜帶您自己的憑證] 或 在此日期移轉至 AFD 標準和進階 。 現有的受控憑證將在 2025 年 8 月 15 日之前自動更新,並持續有效到 2026 年 4 月 14 日為止。 瞭解更多資訊
- 來自 Microsoft 的 Azure CDN 標準 (傳統) 將於 2027 年 9 月 30 日淘汰。 若要避免服務中斷,請移轉至 AFD 標準或進階。 瞭解更多資訊。
- 來自 Edgio 的 Azure CDN 於 2025 年 1 月 15 日淘汰。 瞭解更多資訊。
PowerShell 提供了最具彈性的方法來管理您的 Azure 內容傳遞網路設定檔和端點。 您可以用互動方式使用 PowerShell 或透過撰寫指令碼來自動進行管理工作。 本教學課程會示範數個您可透過 PowerShell 完成的最常見工作,以管理 Azure 內容傳遞網路設定檔和端點。
Prerequisites
Note
建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az。
若要使用 PowerShell 來管理 Azure 內容傳遞網路設定檔和端點,您必須安裝 Azure PowerShell 模組。 若要了解如何安裝 Azure PowerShell 及使用 Connect-AzAccount Cmdlet 連接至 Azure,請參閱 如何安裝和設定 Azure PowerShell。
Important
您必須先使用 Connect-AzAccount 登入,才能執行 Azure PowerShell Cmdlet。
列出 Azure 內容傳遞網路 Cmdlet
您可以使用 Get-Command Cmdlet 列出 Azure 內容傳遞網路的所有 Cmdlet。
PS C:\> Get-Command -Module Az.Cdn
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Confirm-AzCdnEndpointProbeURL 2.1.0 Az.Cdn
Cmdlet Disable-AzCdnCustomDomain 2.1.0 Az.Cdn
Cmdlet Disable-AzCdnCustomDomainHttps 2.1.0 Az.Cdn
Cmdlet Enable-AzCdnCustomDomain 2.1.0 Az.Cdn
Cmdlet Enable-AzCdnCustomDomainHttps 2.1.0 Az.Cdn
Cmdlet Get-AzCdnCustomDomain 2.1.0 Az.Cdn
Cmdlet Get-AzCdnEdgeNode 2.1.0 Az.Cdn
Cmdlet Get-AzCdnEndpoint 2.1.0 Az.Cdn
Cmdlet Get-AzCdnEndpointResourceUsage 2.1.0 Az.Cdn
Cmdlet Get-AzCdnOrigin 2.1.0 Az.Cdn
Cmdlet Get-AzCdnProfile 2.1.0 Az.Cdn
Cmdlet Get-AzCdnProfileResourceUsage 2.1.0 Az.Cdn
Cmdlet Get-AzCdnProfileSupportedOptimizationType 2.1.0 Az.Cdn
Cmdlet Get-AzCdnSubscriptionResourceUsage 2.1.0 Az.Cdn
Cmdlet New-AzCdnCustomDomain 2.1.0 Az.Cdn
Cmdlet New-AzCdnDeliveryPolicy 2.1.0 Az.Cdn
Cmdlet New-AzCdnDeliveryRule 2.1.0 Az.Cdn
Cmdlet New-AzCdnDeliveryRuleAction 2.1.0 Az.Cdn
Cmdlet New-AzCdnDeliveryRuleCondition 2.1.0 Az.Cdn
Cmdlet New-AzCdnEndpoint 2.1.0 Az.Cdn
Cmdlet New-AzCdnProfile 2.1.0 Az.Cdn
Cmdlet Remove-AzCdnCustomDomain 2.1.0 Az.Cdn
Cmdlet Remove-AzCdnEndpoint 2.1.0 Az.Cdn
Cmdlet Remove-AzCdnProfile 2.1.0 Az.Cdn
Cmdlet Set-AzCdnProfile 2.1.0 Az.Cdn
Cmdlet Start-AzCdnEndpoint 2.1.0 Az.Cdn
Cmdlet Stop-AzCdnEndpoint 2.1.0 Az.Cdn
尋求幫助
您可以使用 Get-Help Cmdlet 取得這些 Cmdlet 的說明。 Get-Help 提供使用方式與語法,並選擇性地顯示範例。
PS C:\> Get-Help Get-AzCdnProfile
NAME
Get-AzCdnProfile
SYNOPSIS
Gets an Azure CDN profile.
SYNTAX
Get-AzCdnProfile [-ProfileName <String>] [-ResourceGroupName <String>] [-InformationAction
<ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]
DESCRIPTION
Gets an Azure CDN profile and all related information.
RELATED LINKS
https://learn.microsoft.com/powershell/module/az.cdn/get-azcdnprofile
REMARKS
To see the examples, type: "get-help Get-AzCdnProfile -examples".
For more information, type: "get-help Get-AzCdnProfile -detailed".
For technical information, type: "get-help Get-AzCdnProfile -full".
For online help, type: "get-help Get-AzCdnProfile -online"
列出現有的 Azure 內容傳遞網路設定檔
不含任何參數的 Get-AzCdnProfile Cmdlet 會擷取所有現有的 內容傳遞網路設定檔。
Get-AzCdnProfile
此輸出可以輸送到 Cmdlet 以便列舉。
# Output the name of all profiles on this subscription.
Get-AzCdnProfile | ForEach-Object { Write-Host $_.Name }
您也可以透過指定個人檔案名稱和資源群組,來傳回單一的個人檔案。
Get-AzCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG
Tip
可能會有多個具有相同名稱的內容傳遞網路設定檔,只要它們位於不同的資源群組即可。 省略 ResourceGroupName 參數會傳回所有具有相符名稱的設定檔。
列出現有的內容傳遞網路端點
Get-AzCdnEndpoint 可以擷取設定檔上的個別端點或所有端點。
# Get a single endpoint.
Get-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo
# Get all of the endpoints on a given profile.
Get-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG
建立內容傳遞網路設定檔與端點
New-AzCdnProfile 和 New-AzCdnEndpoint 可用來建立內容傳遞網路設定檔與端點。 支援以下 SKU:
- Standard_Verizon
- Premium_Verizon
- Custom_Verizon
- Standard_Microsoft
- Standard_ChinaCdn
# Create a new profile
New-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku Standard_Microsoft -Location "Central US"
# Create a new endpoint
$origin = @{
Name = "Contoso"
HostName = "www.contoso.com"
};
New-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Location "Central US" -EndpointName cdnposhdoc -Origin $origin
新增自訂網域
New-AzCdnCustomDomain 會將自訂網域名稱新增至現有端點。
Important
您必須以 [如何將自訂網域對應至內容傳遞網路端點] 中所述方式,透過您的 DNS 提供者設定 CNAME。 您可以先測試對應,然後使用 Test-AzCdnCustomDomain修改端點。
# Create the custom domain on the endpoint
New-AzCdnCustomDomain -ResourceGroupName CdnDemoRG -ProfileName CdnPoshDemo -Name contoso -HostName "cdn.contoso.com" -EndpointName cdnposhdoc
修改端點
Update-AzCdnEndpoint 可修改現有的端點。
# Update endpoint with compression settings
Update-AzCdnEndpoint -Name cdnposhdoc -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -IsCompressionEnabled -ContentTypesToCompress "text/javascript","text/css","application/json"
Purging
Clear-AzCdnEndpointContent 會清除快取的資產。
# Purge some assets.
Clear-AzCdnEndpointContent -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc -ContentFilePath @("/images/kitten.png","/video/rickroll.mp4")
啟動/停止內容傳遞網路端點
Start-AzCdnEndpoint 和 Stop-AzCdnEndpoint 可用來啟動和停止個別端點或端點群組。
# Stop the CdnPoshDemo endpoint
Stop-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Name cdnposhdoc
# Start the CdnPoshDemo endpoint
Start-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Name cdnposhdoc
建立標準規則引擎原則,並套用至現有的內容傳遞網路端點
下列 Cmdlet 清單可用來建立標準規則引擎原則,並將其套用至現有的內容傳遞網路端點。
Conditions:
- New-AzFrontDoorCdnRuleCookiesConditionObject
- New-AzCdnDeliveryRuleHttpVersionConditionObject
- New-AzCdnDeliveryRuleIsDeviceConditionObject
- New-AzCdnDeliveryRulePostArgsConditionObject
- New-AzCdnDeliveryRuleQueryStringConditionObject
- New-AzCdnDeliveryRuleRemoteAddressConditionObject
- New-AzCdnDeliveryRuleRequestBodyConditionObject
- New-AzCdnDeliveryRuleRequestHeaderConditionObject
- New-AzCdnDeliveryRuleRequestMethodConditionObject
- New-AzCdnDeliveryRuleRequestSchemeConditionObject
- New-AzCdnDeliveryRuleRequestUriConditionObject
- New-AzCdnDeliveryRuleResponseHeaderActionObject
- New-AzCdnDeliveryRuleUrlFileExtensionConditionObject
- New-AzCdnDeliveryRuleUrlFileNameConditionObject
- New-AzCdnDeliveryRuleUrlPathConditionObject
Actions:
- New-AzCdnDeliveryRuleRequestHeaderActionObject
- New-AzCdnDeliveryRuleRequestHeaderActionObject
- New-AzCdnUrlRedirectActionObject
- New-AzCdnUrlRewriteActionObject
- New-AzCdnUrlSigningActionObject
# Create a path based Response header modification rule.
$cond1 = New-AzCdnDeliveryRuleUrlPathConditionObject -Name UrlPath -ParameterOperator BeginsWith -ParameterMatchValue "/images/"
$action1 = New-AzCdnDeliveryRuleResponseHeaderActionObject -Name ModifyResponseHeader -ParameterHeaderAction Overwrite -ParameterHeaderName "Access-Control-Allow-Origin" -ParameterValue "*"
$rule1 = New-AzCdnDeliveryRuleObject -Name "PathBasedCacheOverride" -Order 1 -Condition $cond1 -Action $action1
# Create a new http to https redirect rule
$cond1 = New-AzCdnDeliveryRuleRequestSchemeConditionObject -Name RequestScheme -ParameterMatchValue HTTPS
$action1 = New-AzCdnUrlRedirectActionObject -Name UrlRedirect -ParameterRedirectType Found -ParameterDestinationProtocol Https
$rule2 = New-AzCdnDeliveryRuleObject -Name "UrlRewriteRule" -Order 2 -Condition $cond1 -Action $action1
# Update existing endpoint with new rules
Update-AzCdnEndpoint -Name cdnposhdoc -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -DeliveryPolicyRule $rule1,$rule2
刪除內容傳遞網路資源
Remove-AzCdnProfile 和 Remove-AzCdnEndpoint 可用來移除設定檔和端點。
# Remove a single endpoint
Remove-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc
# Remove a single profile
Remove-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG