PowerShell ile Bir Azure aboneliği için olaylara abone olma

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

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

Ö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 an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Select the Azure subscription you want to subscribe to. You need this command only if the 
# current subscription is not the one you wish to subscribe to.
Set-AzContext -Subscription "<subscription-name-or-ID>"

# Subscribe to the Azure subscription. The command creates the subscription for the currently selected Azure subscription. 
New-AzEventGridSubscription -Endpoint $myEndpoint -EventSubscriptionName demoSubscriptionToAzureSub

Örnek betik - önizleme modülü

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

Ö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 an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Get the subscription ID
$subID = (Get-AzureRmSubscription -SubscriptionName "<subscription-name>").Id

# Subscribe to the Azure subscription. The command creates the subscription for the currently selected Azure subscription. 
New-AzureRmEventGridSubscription -ResourceId "/subscriptions/$subID" -Endpoint $myEndpoint -EventSubscriptionName demoSubscriptionToAzureSub

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