Use PowerShell to create an Azure notification hub
This sample PowerShell script creates a sample Azure notification hub.
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
This sample requires Azure PowerShell Az 1.0 or later. Run Get-Module -ListAvailable Az
to see which versions are installed.
If you need to install, see Install Azure PowerShell module.
Run Connect-AzAccount to sign in to Azure.
Prerequisites
- Azure subscription - If you don't have an Azure subscription, create a free account before you begin.
Sample script
# 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
Clean up deployment
After you run the sample script, you can use the following command to remove the resource group and all resources associated with it:
Remove-AzResourceGroup -ResourceGroupName $resourceGroupName
Script explanation
This script uses the following commands:
Command | Notes |
---|---|
New-AzResourceGroup | Creates a resource group in which all resources are stored. |
New-AzNotificationHubsNamespace | Creates a namespace for the notification hub. |
New-AzNotificationHub | Creates a notification hub. |
Remove-AzResourceGroup | Deletes a resource group including all nested resources. |
Next steps
For more information on the Azure PowerShell, see Azure PowerShell documentation.