Gestire la rete CDN di Azure con PowerShellManage Azure CDN with PowerShell

PowerShell offre uno dei metodi più flessibili per gestire i profili e gli endpoint della rete CDN.PowerShell provides one of the most flexible methods to manage your Azure CDN profiles and endpoints. È possibile usare PowerShell in modo interattivo o scrivendo script per automatizzare le attività di gestione.You can use PowerShell interactively or by writing scripts to automate management tasks. Questa esercitazione illustra alcune delle attività più comuni che è possibile eseguire con PowerShell per gestire i profili e gli endpoint della rete CDN di Azure.This tutorial demonstrates several of the most common tasks you can accomplish with PowerShell to manage your Azure CDN profiles and endpoints.

PrerequisitiPrerequisites

Per usare PowerShell per gestire i profili e gli endpoint della rete CDN di Azure, è necessario avere il modulo Azure PowerShell installato.To use PowerShell to manage your Azure CDN profiles and endpoints, you must have the Azure PowerShell module installed. Per informazioni su come installare Azure PowerShell e connettersi ad Azure usando il cmdlet Login-AzureRmAccountCome installare e configurare Azure PowerShell.To learn how to install Azure PowerShell and connect to Azure using the Login-AzureRmAccount cmdlet, see How to install and configure Azure PowerShell.

Importante

È necessario accedere con Login-AzureRmAccount per poter eseguire i cmdlet di Azure PowerShell.You must log in with Login-AzureRmAccount before you can execute Azure PowerShell cmdlets.

Inclusione in elenco dei cmdlet della rete CDN di AzureListing the Azure CDN cmdlets

È elencare tutti i cmdlet della rete CDN di Azure usando il cmdlet Get-Command .You can list all the Azure CDN cmdlets using the Get-Command cmdlet.

PS C:\> Get-Command -Module AzureRM.Cdn

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-AzureRmCdnCustomDomain                         2.0.0      AzureRm.Cdn
Cmdlet          Get-AzureRmCdnEndpoint                             2.0.0      AzureRm.Cdn
Cmdlet          Get-AzureRmCdnEndpointNameAvailability             2.0.0      AzureRm.Cdn
Cmdlet          Get-AzureRmCdnOrigin                               2.0.0      AzureRm.Cdn
Cmdlet          Get-AzureRmCdnProfile                              2.0.0      AzureRm.Cdn
Cmdlet          Get-AzureRmCdnProfileSsoUrl                        2.0.0      AzureRm.Cdn
Cmdlet          New-AzureRmCdnCustomDomain                         2.0.0      AzureRm.Cdn
Cmdlet          New-AzureRmCdnEndpoint                             2.0.0      AzureRm.Cdn
Cmdlet          New-AzureRmCdnProfile                              2.0.0      AzureRm.Cdn
Cmdlet          Publish-AzureRmCdnEndpointContent                  2.0.0      AzureRm.Cdn
Cmdlet          Remove-AzureRmCdnCustomDomain                      2.0.0      AzureRm.Cdn
Cmdlet          Remove-AzureRmCdnEndpoint                          2.0.0      AzureRm.Cdn
Cmdlet          Remove-AzureRmCdnProfile                           2.0.0      AzureRm.Cdn
Cmdlet          Set-AzureRmCdnEndpoint                             2.0.0      AzureRm.Cdn
Cmdlet          Set-AzureRmCdnOrigin                               2.0.0      AzureRm.Cdn
Cmdlet          Set-AzureRmCdnProfile                              2.0.0      AzureRm.Cdn
Cmdlet          Start-AzureRmCdnEndpoint                           2.0.0      AzureRm.Cdn
Cmdlet          Stop-AzureRmCdnEndpoint                            2.0.0      AzureRm.Cdn
Cmdlet          Test-AzureRmCdnCustomDomain                        2.0.0      AzureRm.Cdn
Cmdlet          Unpublish-AzureRmCdnEndpointContent                2.0.0      AzureRm.Cdn

Risorse della GuidaGetting help

È possibile visualizzare la Guida con uno di questi cmdlet usando il cmdlet Get-Help .You can get help with any of these cmdlets using the Get-Help cmdlet. Get-Help fornisce la sintassi e facoltativamente illustra gli esempi.Get-Help provides usage and syntax, and optionally shows examples.

PS C:\> Get-Help Get-AzureRmCdnProfile

NAME
    Get-AzureRmCdnProfile

SYNOPSIS
    Gets an Azure CDN profile.


SYNTAX
    Get-AzureRmCdnProfile [-ProfileName <String>] [-ResourceGroupName <String>] [-InformationAction
    <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]


DESCRIPTION
    Gets an Azure CDN profile and all related information.


RELATED LINKS

REMARKS
    To see the examples, type: "get-help Get-AzureRmCdnProfile -examples".
    For more information, type: "get-help Get-AzureRmCdnProfile -detailed".
    For technical information, type: "get-help Get-AzureRmCdnProfile -full".

Inclusione in elenco dei profili della rete CDN di Azure esistentiListing existing Azure CDN profiles

Il cmdlet Get-AzureRmCdnProfile senza alcun parametro recupera tutti i profili della rete CDN esistenti.The Get-AzureRmCdnProfile cmdlet without any parameters retrieves all your existing CDN profiles.

Get-AzureRmCdnProfile

È possibile inviare pipe di questo output ai cmdlet per l'enumerazione.This output can be piped to cmdlets for enumeration.

# Output the name of all profiles on this subscription.
Get-AzureRmCdnProfile | ForEach-Object { Write-Host $_.Name }

# Return only **Azure CDN from Verizon** profiles.
Get-AzureRmCdnProfile | Where-Object { $_.Sku.Name -eq "StandardVerizon" }

È anche possibile restituire un solo profilo specificando il gruppo di risorse e il nome del profilo.You can also return a single profile by specifying the profile name and resource group.

Get-AzureRmCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

Suggerimento

È possibile avere più profili della rete CDN con lo stesso nome, purché siano in gruppi di risorse diversi.It is possible to have multiple CDN profiles with the same name, so long as they are in different resource groups. Se si omette il parametro ResourceGroupName , vengono restituiti tutti i profili con un nome corrispondente.Omitting the ResourceGroupName parameter returns all profiles with a matching name.

Inclusione in elenco degli endpoint della rete CDN esistentiListing existing CDN endpoints

Get-AzureRmCdnEndpoint può recuperare un singolo endpoint o tutti gli endpoint in un profilo.Get-AzureRmCdnEndpoint can retrieve an individual endpoint or all the endpoints on a profile.

# Get a single endpoint.
Get-AzureRmCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo

# Get all of the endpoints on a given profile. 
Get-AzureRmCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

# Return all of the endpoints on all of the profiles.
Get-AzureRmCdnProfile | Get-AzureRmCdnEndpoint

# Return all of the endpoints in this subscription that are currently running.
Get-AzureRmCdnProfile | Get-AzureRmCdnEndpoint | Where-Object { $_.ResourceState -eq "Running" }

Creazione dei profili e degli endpoint della rete CDNCreating CDN profiles and endpoints

New-AzureRmCdnProfile e New-AzureRmCdnEndpoint vengono usati per creare profili ed endpoint della rete CDN.New-AzureRmCdnProfile and New-AzureRmCdnEndpoint are used to create CDN profiles and endpoints.

# Create a new profile
New-AzureRmCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku StandardAkamai -Location "Central US"

# Create a new endpoint
New-AzureRmCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Location "Central US" -EndpointName cdnposhdoc -OriginName "Contoso" -OriginHostName "www.contoso.com"

# Create a new profile and endpoint (same as above) in one line
New-AzureRmCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku StandardAkamai -Location "Central US" | New-AzureRmCdnEndpoint -EndpointName cdnposhdoc -OriginName "Contoso" -OriginHostName "www.contoso.com"

Controllo della disponibilità del nome dell'endpointChecking endpoint name availability

Get-AzureRmCdnEndpointNameAvailability restituisce un oggetto indicante se un nome di endpoint è disponibile.Get-AzureRmCdnEndpointNameAvailability returns an object indicating if an endpoint name is available.

# Retrieve availability
$availability = Get-AzureRmCdnEndpointNameAvailability -EndpointName "cdnposhdoc"

# If available, write a message to the console.
If($availability.NameAvailable) { Write-Host "Yes, that endpoint name is available." }
Else { Write-Host "No, that endpoint name is not available." }

Aggiunta di un dominio personalizzatoAdding a custom domain

New-AzureRmCdnCustomDomain aggiunge un nome di dominio personalizzato a un endpoint esistente.New-AzureRmCdnCustomDomain adds a custom domain name to an existing endpoint.

Importante

È necessario configurare CNAME con il provider DNS, come illustrato in Come eseguire il mapping di un dominio personalizzato all'endpoint della rete per la distribuzione di contenuti (rete CDN).You must set up the CNAME with your DNS provider as described in How to map Custom Domain to Content Delivery Network (CDN) endpoint. È possibile testare il mapping prima di modificare l'endpoint usando Test-AzureRmCdnCustomDomain.You can test the mapping before modifying your endpoint using Test-AzureRmCdnCustomDomain.

# Get an existing endpoint
$endpoint = Get-AzureRmCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc

# Check the mapping
$result = Test-AzureRmCdnCustomDomain -CdnEndpoint $endpoint -CustomDomainHostName "cdn.contoso.com"

# Create the custom domain on the endpoint
If($result.CustomDomainValidated){ New-AzureRmCdnCustomDomain -CustomDomainName Contoso -HostName "cdn.contoso.com" -CdnEndpoint $endpoint }

Modifica di un endpointModifying an endpoint

Set-AzureRmCdnEndpoint modifica un endpoint esistente.Set-AzureRmCdnEndpoint modifies an existing endpoint.

# Get an existing endpoint
$endpoint = Get-AzureRmCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc

# Set up content compression
$endpoint.IsCompressionEnabled = $true
$endpoint.ContentTypesToCompress = "text/javascript","text/css","application/json"

# Save the changed endpoint and apply the changes
Set-AzureRmCdnEndpoint -CdnEndpoint $endpoint

Ripulitura/Precaricamento degli asset della rete CDNPurging/Pre-loading CDN assets

Unpublish-AzureRmCdnEndpointContent ripulisce gli asset nella cache, mentre Publish-AzureRmCdnEndpointContent precarica gli asset negli endpoint supportati.Unpublish-AzureRmCdnEndpointContent purges cached assets, while Publish-AzureRmCdnEndpointContent pre-loads assets on supported endpoints.

# Purge some assets.
Unpublish-AzureRmCdnEndpointContent -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo -PurgeContent "/images/kitten.png","/video/rickroll.mp4"

# Pre-load some assets.
Publish-AzureRmCdnEndpointContent -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo -LoadContent "/images/kitten.png","/video/rickroll.mp4"

# Purge everything in /images/ on all endpoints.
Get-AzureRmCdnProfile | Get-AzureRmCdnEndpoint | Unpublish-AzureRmCdnEndpointContent -PurgeContent "/images/*"

Avvio/Arresto degli endpoint della rete CDNStarting/Stopping CDN endpoints

Start-AzureRmCdnEndpoint e Stop-AzureRmCdnEndpoint possono essere usati per avviare e arrestare singoli endpoint o gruppi di endpoint.Start-AzureRmCdnEndpoint and Stop-AzureRmCdnEndpoint can be used to start and stop individual endpoints or groups of endpoints.

# Stop the cdndocdemo endpoint
Stop-AzureRmCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo

# Stop all endpoints
Get-AzureRmCdnProfile | Get-AzureRmCdnEndpoint | Stop-AzureRmCdnEndpoint

# Start all endpoints
Get-AzureRmCdnProfile | Get-AzureRmCdnEndpoint | Start-AzureRmCdnEndpoint

Eliminazione di risorse della rete CDNDeleting CDN resources

Remove-AzureRmCdnProfile e Remove-AzureRmCdnEndpoint possono essere usati per rimuovere profili ed endpoint.Remove-AzureRmCdnProfile and Remove-AzureRmCdnEndpoint can be used to remove profiles and endpoints.

# Remove a single endpoint
Remove-AzureRmCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc

# Remove all the endpoints on a profile and skip confirmation (-Force)
Get-AzureRmCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG | Get-AzureRmCdnEndpoint | Remove-AzureRmCdnEndpoint -Force

# Remove a single profile
Remove-AzureRmCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG

Passaggi successiviNext Steps

Informazioni su come automatizzare la rete CDN di Azure con .NET o Node.js.Learn how to automate Azure CDN with .NET or Node.js.

Per informazioni sulle funzionalità della rete CDN, vedere Panoramica della rete per la distribuzione di contenuti (rete CDN) di Azure.To learn about CDN features, see CDN Overview.