次の方法で共有


PowerShell を使用して Azure 通知ハブを作成する

この PowerShell のサンプル スクリプトは、Azure 通知ハブのサンプルを作成します。

Note

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、「Azure PowerShell のインストール」を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

このサンプルには、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

スクリプトの説明

このスクリプトでは以下のコマンドを使用します。

コマンド メモ
New-AzResourceGroup すべてのリソースを格納するリソース グループを作成します。
New-AzNotificationHubsNamespace 通知ハブの名前空間を作成します。
New-AzNotificationHub 通知ハブを作成します。
Remove-AzResourceGroup 入れ子になったリソースすべてを含むリソース グループを削除します。

次のステップ

Azure PowerShell の詳細については、Azure PowerShell のドキュメントを参照してください。