Bagikan melalui


Menggunakan PowerShell untuk membuat hub pemberitahuan Azure

Contoh skrip PowerShell ini membuat contoh hub pemberitahuan Azure.

Catatan

Kami menyarankan agar 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.

Sampel ini memerlukan Azure PowerShell Az 1.0 atau yang lebih baru. Jalankan Get-Module -ListAvailable Az untuk melihat versi mana yang dipasang. Jika Anda perlu memasang, lihat Pasang modul Azure PowerShell.

Jalankan Connect-AzAccount untuk masuk ke Azure.

Prasyarat

  • Langganan Azure - Jika Anda belum memiliki langganan Azure, buat akun gratis sebelum Anda memulai.

Contoh skrip

# Set appropriate values for these variables
$resourceGroupName = "<Enter a name for the resource group>"
$nhubnamespace = "<Enter a name for the notification hub namespace>"
$location = "East US"

# Create a resource group.
New-AzResourceGroup -Name $resourceGroupName -Location $location

# Create a namespace for the resource group
New-AzNotificationHubsNamespace -ResourceGroup $resourceGroupName -Namespace $nhubnamespace -Location $location

# Create an input JSON file that you use with the New-AzNotificationHub command
$text = '{"name": "MyNotificationHub",  "Location": "East US",  "Properties": {  }}'
$text | Out-File "inputfile2.json"

# Create a notification hub
New-AzNotificationHub -ResourceGroup $resourceGroupName -Namespace $nhubnamespace -InputFile .\inputfile.json

Membersihkan penyebaran

Setelah menjalankan sampel skrip, Anda dapat menggunakan perintah berikut untuk menghapus grup sumber daya dan semua sumber daya yang terkait:

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

Penjelasan skrip

Skrip ini menggunakan perintah berikut:

Perintah Catatan
Baru-AzResourceGroup Membuat grup sumber daya tempat semua sumber daya disimpan.
New-AzNotificationHubsNamespace Membuat namespace layanan untuk hub pemberitahuan.
New-AzNotificationHub Membuat hub pemberitahuan.
Remove-AzResourceGroup Menghapus grup sumber daya termasuk semua sumber daya berlapis.

Langkah berikutnya

Untuk informasi selengkapnya tentang Azure PowerShell, lihat dokumentasi Azure PowerShell.