使用 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 來登入 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-AzNotificationHubsNamespace 建立通知中樞的命名空間。
New-AzNotificationHub 建立通知中樞。
Remove-AzResourceGroup 刪除資源群組,包括所有的巢狀資源。

下一步

如需有關 Azure PowerShell 的詳細資訊,請參閱 Azure PowerShell 文件