Share via


查詢 Event Grid 訂用帳戶

本文章說明如何列出您的 Azure 訂用帳戶中的 Event Grid 訂用帳戶。 查詢現有的 Event Grid 訂用帳戶時,請務必瞭解不同類型的訂用帳戶。 您可根據您想要取得的訂用帳戶類型來提供不同的參數。

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

資源群組和 Azure 訂用帳戶

Azure 訂用帳戶和資源群組都不是 Azure 資源。 因此,資源群組或 Azure 訂用帳戶的事件方格訂用帳戶與 Azure 資源的事件方格訂用帳戶沒有相同的屬性。 資源群組或 Azure 訂用帳戶的事件方格訂用帳戶會被視為全域。

若要取得 Azure 訂用帳戶及其資源群組的事件方格訂用帳戶,您不需要提供任何參數。 確定您已選取您想要查詢的 Azure 訂用帳戶。 下列範例不會取得自定義主題或 Azure 資源的 Event Grid 訂用帳戶。

對於 Azure CLI,請使用:

az account set -s "My Azure Subscription"
az eventgrid event-subscription list

對於 PowerShell,請使用:

Set-AzContext -Subscription "My Azure Subscription"
Get-AzEventGridSubscription

若要取得 Azure 訂用帳戶的事件方格訂用帳戶,請提供 Microsoft.Resources.Subscriptions 的主題類型。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --topic-type-name "Microsoft.Resources.Subscriptions" --location global

對於 PowerShell,請使用:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Resources.Subscriptions"

若要取得 Azure 訂用帳戶內所有資源群組的事件 方格訂用帳戶,請提供 Microsoft.Resources.ResourceGroups 的主題類型。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --topic-type-name "Microsoft.Resources.ResourceGroups" --location global

對於 PowerShell,請使用:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Resources.ResourceGroups"

若要取得指定資源群組的事件方格訂用帳戶,請提供資源群組的名稱做為參數。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --resource-group myResourceGroup --location global

對於 PowerShell,請使用:

Get-AzEventGridSubscription -ResourceGroupName myResourceGroup

自訂主題和 Azure 資源

事件方格自定義主題是 Azure 資源。 因此,您會以相同方式查詢事件方格訂用帳戶,以取得自定義主題和其他資源,例如 Blob 儲存器帳戶。 若要取得自定義主題的事件方格訂用帳戶,您必須提供可識別資源或識別資源位置的參數。 您無法廣泛查詢 Azure 訂用帳戶中的資源事件方格訂用帳戶。

若要取得位置中自定義主題和其他資源的 Event Grid 訂用帳戶,請提供位置的名稱。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --location westus2

對於 PowerShell,請使用:

Get-AzEventGridSubscription -Location westus2

若要取得某個位置中自訂主題的訂用帳戶,請提供位置和 Microsoft.EventGrid.Topics 主題類型。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --topic-type-name "Microsoft.EventGrid.Topics" --location "westus2"

對於 PowerShell,請使用:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.EventGrid.Topics" -Location westus2

若要取得某個位置中儲存體帳戶的訂用帳戶,請提供位置和 Microsoft.Storage.StorageAccounts 主題類型。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --topic-type "Microsoft.Storage.StorageAccounts" --location westus2

對於 PowerShell,請使用:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Storage.StorageAccounts" -Location westus2

若要取得自定義主題的事件方格訂用帳戶,請提供自定義主題的名稱及其資源群組的名稱。

對於 Azure CLI,請使用:

az eventgrid event-subscription list --topic-name myCustomTopic --resource-group myResourceGroup

對於 PowerShell,請使用:

Get-AzEventGridSubscription -TopicName myCustomTopic -ResourceGroupName myResourceGroup

若要取得特定資源的 Event Grid 訂用帳戶,請提供資源識別符。

對於 Azure CLI,請使用:

resourceid=$(az storage account show -g myResourceGroup -n myStorageAccount --query id --output tsv)
az eventgrid event-subscription list --resource-id $resourceid

對於 PowerShell,請使用:

$resourceid = (Get-AzResource -Name mystorage -ResourceGroupName myResourceGroup).ResourceId
Get-AzEventGridSubscription -ResourceId $resourceid

下一步