Feliratkozás egy egyéni témakör eseményeire a PowerShell-lel

Ez a szkript létrehoz egy Event Grid-előfizetést egy egyéni témakör eseményeihez.

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

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

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 the name of the topic you are subscribing to
$myTopic = "<your-custom-topic-name>"

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

# Provide a name for resource group to create. It will contain the custom event.
$myResourceGroup = "<resource-group-name>"

# Create resource group
New-AzResourceGroup -Name $myResourceGroup -Location westus2

# Create custom topic
New-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $myTopic -Location westus2 

# Subscribe to the custom event. Include the resource group that contains the custom topic.
New-AzEventGridSubscription `
  -EventSubscriptionName demoSubscription `
  -Endpoint $myEndpoint `
  -ResourceGroupName $myResourceGroup `
  -TopicName $myTopic

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

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 the name of the topic you are subscribing to
$myTopic = "<your-custom-topic-name>"

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

# Provide the name of the resource group to create. It will contain the custom topic.
$myResourceGroup = "<resource-group-name>"

# Create resource group
New-AzResourceGroup -Name $myResourceGroup -Location westus2

# Create custom topic and get its resource ID.
$topicID = (New-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $myTopic -Location westus2).Id 

# Subscribe to the custom event. Include the resource group that contains the custom topic.
New-AzEventGridSubscription `
  -ResourceId $topicID `
  -EventSubscriptionName demoSubscription `
  -Endpoint $myEndpoint 

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