使用 PowerShell 订阅 Blob 存储帐户的事件

此脚本创建 Blob 存储帐户事件的事件网格订阅。

注意

建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

如果没有 Azure 订阅,可在开始前创建一个试用帐户

示例脚本 - 稳定版

# Provide a unique name for the Blob storage account.
$storageName = "<your-unique-storage-name>"

# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Provide the name of the resource group to create. It will contain the storage account.
$myResourceGroup="<resource-group-name>"

# Create resource group
New-AzResourceGroup -Name $myResourceGroup -Location chinanorth2

# Create the Blob storage account. 
New-AzStorageAccount -ResourceGroupName $myResourceGroup `
  -Name $storageName `
  -Location chinanorth2 `
  -SkuName Standard_LRS `
  -Kind BlobStorage `
  -AccessTier Hot

# Get the resource ID of the Blob storage account.
$storageId = (Get-AzStorageAccount -ResourceGroupName $myResourceGroup -AccountName $storageName).Id

# Subscribe to the Blob storage account. 
New-AzEventGridSubscription `
  -EventSubscriptionName demoSubToStorage `
  -Endpoint $myEndpoint `
  -ResourceId $storageId

脚本说明

此脚本使用以下命令创建事件订阅。 表中的每条命令链接到特定于命令的文档。

命令 说明
New-AzEventGridSubscription 创建事件网格订阅。

后续步骤