Share via


Feliratkozás egy Azure-előfizetés eseményeire a PowerShell-lel

Ez a szkript létrehoz egy Event Grid-előfizetést egy Azure-előfizetés eseményeihez.

If you don't have an Azure subscription, create an Azure free account before you begin.

Példaszkript – stabil

Megjegyzés:

We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Select the Azure subscription you want to subscribe to. You need this command only if the 
# current subscription is not the one you wish to subscribe to.
Set-AzContext -Subscription "<subscription-name-or-ID>"

# Subscribe to the Azure subscription. The command creates the subscription for the currently selected Azure subscription. 
New-AzEventGridSubscription -Endpoint $myEndpoint -EventSubscriptionName demoSubscriptionToAzureSub

Példaszkript – előzetes verziójú modul

Ehhez az előzetes mintaszkripthez az Event Grid modul szükséges. A telepítéshez futtassa a Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery

Fontos

A PowerShellből származó Azure-funkció használatához telepíteni kell a modult AzureRM . Ez egy régebbi modul, amely csak a Windows PowerShell 5.1-hez érhető el, és már nem kap új funkciókat. A Az modulok és AzureRM a modulok nem kompatibilisek, ha a PowerShell ugyanazon verzióira vannak telepítve. Ha mindkét verzióra szüksége van:

  1. Távolítsa el az Az modult egy PowerShell 5.1-munkamenetből.
  2. Telepítse az AzureRM modult egy PowerShell 5.1-munkamenetből.
  3. Töltse le és telepítse a PowerShell Core 6.x vagy újabb verzióját.
  4. Telepítse az Az modult egy PowerShell Core-munkamenetben.
# You must have the latest version of the Event Grid PowerShell module.
# To install:
# Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery

# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Get the subscription ID
$subID = (Get-AzureRmSubscription -SubscriptionName "<subscription-name>").Id

# Subscribe to the Azure subscription. The command creates the subscription for the currently selected Azure subscription. 
New-AzureRmEventGridSubscription -ResourceId "/subscriptions/$subID" -Endpoint $myEndpoint -EventSubscriptionName demoSubscriptionToAzureSub

Szkript ismertetése

A szkript a következő parancsot használja az esemény-előfizetés létrehozásához. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
New-AzEventGridSubscription Event Grid-előfizetés létrehozása.

Következő lépések