Prenumererar på händelser för en resursgrupp med PowerShell
Det här skriptet skapar en Event Grid-prenumeration på händelser för en resursgrupp.
Om du inte har en Azure-prenumeration skapar du ett kostnadsfritt Azure-konto innan du börjar.
Förhandsversionen av exempelskriptet kräver Event Grid-modulen. Installera genom att köra Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery
Exempelskript – stabilt
Kommentar
Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Se Installera Azure PowerShell för att komma igång. Information om hur du migrerar till Az PowerShell-modulen finns i artikeln om att migrera Azure PowerShell från AzureRM till 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
Exempelskript – modul för förhandsversion
Viktigt!
Om du använder den här Azure-funktionen från PowerShell måste modulen AzureRM
vara installerad. Det här är en äldre modul som bara är tillgänglig för Windows PowerShell 5.1 som inte längre tar emot nya funktioner.
Modulerna Az
och AzureRM
är inte kompatibla när de installeras för samma versioner av PowerShell.
Om du behöver båda versionerna:
- Avinstallera Az-modulen från en PowerShell 5.1-session.
- Installera AzureRM-modulen från en PowerShell 5.1-session.
- Ladda ned och installera PowerShell Core 6.x eller senare.
- Installera Az-modulen i en PowerShell Core-session.
# 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
Förklaring av skript
Det här skriptet använder följande kommandon för att skapa händelseprenumerationen. Varje kommando i tabellen länkar till kommandospecifik dokumentation.
Command | Kommentar |
---|---|
New-AzEventGridSubscription | Skapa en Event Grid-prenumeration. |
Nästa steg
- En introduktion till hanterade program finns i Azure Managed Application overview (Översikt över Azure Managed Application).
- Mer information om PowerShell finns i Azure PowerShell-dokumentationen.