使用 PowerShell 创建 Azure 通知中心

此示例 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 -Environment AzureChinaCloud 以登录到由世纪互联运营的 Microsoft 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 = "China East"

# 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": "China East",  "Properties": {  }}'
$text | Out-File "inputfile2.json"

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

清理部署

运行示例脚本后,可以使用以下命令删除资源组以及与其关联的所有资源:

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

脚本说明

此脚本使用以下命令:

命令 注释
New-AzResourceGroup 创建用于存储所有资源的资源组。
New-AzNotificationHubsNamespace 为通知中心创建命名空间。
New-AzNotificationHub 创建通知中心。
Remove-AzResourceGroup 删除资源组,包括所有嵌套的资源。

后续步骤

有关 Azure PowerShell 的详细信息,请参阅 Azure PowerShell 文档