مشاركة عبر


الاشتراك في أحداث لمجموعة موارد مع PowerShell

ينشئ هذا البرنامج النصي اشتراكًا في شبكة الأحداث لأحداث في مجموعة موارد.

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

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

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

إشعار

نوصي باستخدام الوحدة النمطية Azure Az PowerShell للتفاعل مع Azure. للبدء، راجع تثبيت Azure PowerShell. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى 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

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

هام

يتطلب استخدام ميزة 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 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

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

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

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

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