Create Event Grid custom topic with PowerShell
This script creates an Event Grid custom topic.
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.
If you don't have an Azure subscription, create a trial account before you begin.
Sample script
# Give your custom topic a unique name
$myTopic = "<your-custom-topic-name>"
# Provide a name for resource group to create. It will contain the custom event.
$myResourceGroup = "<resource-group-name>"
# Create resource group
New-AzResourceGroup -Name $myResourceGroup -Location chinanorth2
# Create custom topic
New-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $myTopic -Location chinanorth2
# Retrieve endpoint and key to use when publishing to the topic
$endpoint = (Get-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $myTopic).Endpoint
$key = (Get-AzEventGridTopicKey -ResourceGroupName $myResourceGroup -Name $myTopic).Key1
$endpoint
$key
Script explanation
This script uses the following command to create the custom topic. Each command in the table links to command-specific documentation.
Command | Notes |
---|---|
New-AzEventGridTopic | Create an Event Grid custom topic. |
Next steps
- For an introduction to managed applications, see Azure Managed Application overview.
- For more information on PowerShell, see Azure PowerShell documentation.