PowerShell ile bir özel konu için olaylara abone olma

Bu betik, bir özel konu için olaylara bir Event Grid aboneliği oluşturur.

Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

Önizleme örnek betiği Event Grid modülünü gerektirir. Yüklemek için Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery

Örnek betik - kararlı

Dekont

Azure ile etkileşim kurmak için Azure Az PowerShell modülünü kullanmanızı öneririz. Başlamak için bkz. Azure PowerShell'i yükleme. Az PowerShell modülüne nasıl geçeceğinizi öğrenmek için bkz. Azure PowerShell’i AzureRM’den Az’ye geçirme.

# 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

Örnek betik - önizleme modülü

Önemli

PowerShell'in bu Azure özelliğini kullanmak için modülün AzureRM yüklü olması gerekir. Bu, yalnızca Windows PowerShell 5.1'de artık yeni özellikler almayan eski bir modüldür. Az Ve AzureRM modülleri, PowerShell'in aynı sürümleri için yüklendiğinde uyumlu değildir. Her iki sürüme de ihtiyacınız varsa:

  1. PowerShell 5.1 oturumundan Az modülünü kaldırın.
  2. PowerShell 5.1 oturumundan AzureRM modülünü yükleyin.
  3. PowerShell Core 6.x veya üzerini indirin ve yükleyin.
  4. Az modülünü bir PowerShell Core oturumuna yükleyin.
# 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 

Betik açıklaması

Bu betik, olay aboneliğini oluşturmak için aşağıdaki komutu kullanır. Tablodaki her komut, komuta özgü belgelere yönlendirir.

Command Notlar
New-AzEventGridSubscription Event Grid aboneliği oluşturun.

Sonraki adımlar