الاشتراك في أحداث لموضوع مخصص باستخدام PowerShell

ينشئ هذا البرنامج النصي اشتراك Event Grid للأحداث لموضوع مخصص.

إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

نموذج البرنامج النصي للمعاينة يتطلب الوحدة النمطية "شبكة الأحداث". للتثبيت، ما عليك سوى التشغيل Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery

نموذج البرنامج النصي - مستقر

إشعار

نوصي باستخدام الوحدة النمطية Azure Az PowerShell للتفاعل مع Azure. راجع تثبيت Azure PowerShell للبدء. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى Az.

# 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

نموذج البرنامج النصي - وحدة المعاينة

هام

يتطلب استخدام ميزة Azure هذه من PowerShell تثبيت الوحدة النمطية AzureRM . هذه وحدة نمطية قديمة متوفرة فقط في إصدار ويندوز PowerShell 5.1 التي لم تعد تتلقى ميزات جديدة. الوحدتان AzوAzureRMغير متوافقتين عند تثبيتهما لنفس إصدارات PowerShell. إذا كنت بحاجة إلى كلا الإصدارين:

  1. إلغاء تثبيت الوحدة النمطية Az من جلسة عمل PowerShell 5.1.
  2. تثبيت الوحدة النمطية AzureRM من جلسة عمل PowerShell 5.1.
  3. قم بتنزيل PowerShell Core 6.x أو أحدث وتثبيته.
  4. تثبيت الوحدة النمطية Az في جلسة عمل PowerShell Core.
# 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 

شرح السيناريو

يستخدم هذا البرنامج النصي الأمر التالي لإنشاء اشتراك الحدث. يرتبط كل أمر في الجدول بالوثائق الخاصة بالأوامر.

الأمر الملاحظات
New-AzEventGridSubscription إنشاء اشتراك Event Grid.

الخطوات التالية