此範例 PowerShell 指令碼會建立範例 Azure 通知中樞。
備註
建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 開始使用前,請參閱安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az。
此範例需要 Azure PowerShell Az 1.0 或更新版本。 執行 Get-Module -ListAvailable Az 可查看已安裝的版本。
如果您需要安裝,請參閱安裝 Azure PowerShell 模組。
執行 Connect-AzAccount 來登入 Azure。
先決條件
- Azure 訂用帳戶 - 如果您沒有 Azure 訂用帳戶,請先建立 免費帳戶 ,再開始。
範例腳本
# 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
清除部署
執行範例指令碼之後,您可以使用下列命令來移除資源群組及其相關聯的所有資源:
Remove-AzResourceGroup -ResourceGroupName $resourceGroupName
腳本說明
此指令碼會使用下列命令:
| Command | 註釋 |
|---|---|
| New-AzResourceGroup | 建立用來存放所有資源的資源群組。 |
| New-AzNotificationHubs命名空間 | 建立通知中心的命名空間。 |
| New-AzNotificationHub | 建立通知中樞。 |
| Remove-AzResourceGroup | 刪除包含所有巢狀資源的資源群組。 |
後續步驟
如需有關 Azure PowerShell 的詳細資訊,請參閱 Azure PowerShell 文件。