使用 PowerShell 创建事件网格自定义主题Create Event Grid custom topic with PowerShell
此脚本创建事件网格自定义主题。This script creates an Event Grid custom topic.
备注
本文已经过更新,以便使用 Azure Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShell。To get started with the Az PowerShell module, see Install Azure PowerShell. 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az。To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
如果没有 Azure 订阅,可在开始前创建一个试用帐户。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.
CommandCommand | 说明Notes |
---|---|
New-AzEventGridTopicNew-AzEventGridTopic | 创建事件网格自定义主题。Create an Event Grid custom topic. |
后续步骤Next steps
- 有关托管应用程序的简介,请参阅 Azure 托管应用程序概述。For an introduction to managed applications, see Azure Managed Application overview.
- 有关 PowerShell 的详细信息,请参阅 Azure PowerShell 文档。For more information on PowerShell, see Azure PowerShell documentation.