Share via


Feliratkozás egy erőforráscsoport eseményeire a PowerShell-lel

Ez a szkript létrehoz egy Event Grid-előfizetést egy erőforráscsoport 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 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 and subscribe to.
$myResourceGroup="<resource-group-name>"

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

# Subscribe to the resource group. Provide the name of the resource group you want to subscribe to.
New-AzEventGridSubscription `
  -Endpoint $myEndpoint `
  -EventSubscriptionName demoSubscriptionToResourceGroup `
  -ResourceGroupName $myResourceGroup

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 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 and subscribe to.
$myResourceGroup = "<resource-group-name>"

# Create resource group
$resourceGroupID = (New-AzResourceGroup -Name $myResourceGroup -Location westus2).ResourceId

# Subscribe to the resource group. Provide the name of the resource group you want to subscribe to.
New-AzEventGridSubscription `
  -ResourceId $resourceGroupID `
  -Endpoint $myEndpoint `
  -EventSubscriptionName demoSubscriptionToResourceGroup

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