Abonneren op gebeurtenissen voor een aangepaste onderwerp met PowerShell
Met dit script maakt u een Event Grid-abonnement op de gebeurtenissen voor een aangepast onderwerp.
Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.
Voor het voorbeeldscript van de preview is de Event Grid-module vereist. Voer Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery
uit om deze te installeren
Voorbeeldscript - stabiel
Notitie
Het wordt aanbevolen de Azure Az PowerShell-module te gebruiken om te communiceren met Azure. Zie Azure PowerShell installeren om aan de slag te gaan. Raadpleeg Azure PowerShell migreren van AzureRM naar Az om te leren hoe u naar de Azure PowerShell-module migreert.
# 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
Voorbeeldscript - preview-module
Belangrijk
Als u deze Azure-functie van PowerShell wilt gebruiken, moet de AzureRM
-module zijn geïnstalleerd. Dit is een oudere module die alleen beschikbaar is voor Windows PowerShell 5.1, dat geen nieuwe functies meer ontvangt.
De modules Az
en AzureRM
zijn niet compatibel als ze voor dezelfde versies van PowerShell worden geïnstalleerd.
Als u beide versies nodig hebt:
- De Az-module verwijderen vanuit een PowerShell 5.1-sessie.
- De AzureRM-module installeren vanuit een PowerShell 5.1-sessie.
- PowerShell Core 6.x of nieuwer downloaden en installeren.
- De Az-module installeren in een PowerShell Core-sessie.
# 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
Uitleg van het script
In dit script wordt de volgende opdracht gebruikt om het abonnement op de gebeurtenis te maken. Elke opdracht in de tabel is een koppeling naar opdracht-specifieke documentatie.
Opdracht | Opmerkingen |
---|---|
New-AzEventGridSubscription | Hiermee wordt een Event Grid-abonnement gemaakt. |
Volgende stappen
- Zie Overzicht van door Azure beheerde toepassingen voor algemene informatie over beheerde toepassingen.
- Zie Documentatie over Azure PowerShell voor meer informatie over PowerShell.