Berlangganan ke peristiwa untuk langganan Azure dengan PowerShell
Skrip ini membuat langganan Event Grid ke peristiwa untuk langganan Azure.
Jika Anda tidak memiliki Langganan Azure, buat Akun gratis Azure sebelum memulai.
Skrip sampel - stabil
Catatan
Sebaiknya Anda menggunakan modul Azure Az PowerShell untuk berinteraksi dengan Azure. Lihat Menginstal Azure PowerShell untuk memulai. Untuk mempelajari cara bermigrasi ke modul Az PowerShell, lihat Memigrasikan Azure PowerShell dari AzureRM ke Az.
# 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
Sampel skrip - modul pratinjau
Sampel pratinjau skrip memerlukan modul Event Grid. Untuk menginstal, jalankan Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery
Penting
Untuk menggunakan fitur Azure ini dari PowerShell wajib menginstal modul AzureRM
. Ini adalah modul lama yang hanya tersedia untuk Windows PowerShell 5.1 yang tidak lagi mendapatkan fitur baru.
Modul Az
dan AzureRM
tidak kompatibel ketika diinstal untuk versi PowerShell yang sama.
Jika Anda memerlukan kedua versi:
- Hapus instalan modul Az dari sesi PowerShell 5.1.
- Instal modul AzureRM dari sesi PowerShell 5.1.
- Unduh dan instal PowerShell Core 6.x atau yang lebih baru.
- Instal modul Az dalam sesi 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>"
# 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
Penjelasan skrip
Skrip ini menggunakan perintah berikut untuk membuat langganan peristiwa. Setiap perintah dalam tabel ditautkan ke dokumentasi spesifik-perintah.
Perintah | Catatan |
---|---|
New-AzEventGridSubscription | Membuat langganan Event Grid. |
Langkah berikutnya
- Untuk pengenalan aplikasi terkelola, lihat Ringkasan Azure Managed Application.
- Untuk informasi selengkapnya tentang PowerShell, lihat Dokumentasi Azure PowerShell.