このサンプル 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 のドキュメントを参照してください。