本文介绍如何使用 Azure 门户、PowerShell 或 Azure CLI 获取 Azure 存储帐户的配置信息和属性。
获取存储帐户的资源 ID
每个 Azure 资源管理器资源都有一个对其唯一标识的关联资源 ID。 某些操作需要提供资源 ID。 你可以通过使用 Azure 门户、PowerShell 或 Azure CLI 获取存储帐户的资源 ID。
若要在 Azure 门户中显示存储帐户的 Azure 资源管理器的资源 ID,请执行以下步骤:
导航到 Azure 门户中的存储帐户。
在“概述”页面的“Essentials”分区,选择“JSON 视图”链接。
存储帐户的资源 ID 显示在页面顶部。
若要使用 PowerShell 返回存储帐户的 Azure 资源管理器资源 ID,请确保已安装 Az.Storage 模块。 接下来,调用 Get-AzStorageAccount 命令以返回存储帐户并获取其资源 ID:
(Get-AzStorageAccount -ResourceGroupName <resource-group> -Name <storage-account>).Id
使用 Azure CLI 返回存储帐户的 Azure 资源管理器的资源 ID,调用 az storage account show 命令并查询资源 ID:
az storage account show \
--name <storage-account> \
--resource-group <resource-group> \
--query id \
--output tsv
还可通过在 REST API 中调用“帐户 - 获取属性”操作来获取存储帐户的资源 ID。
有关 Azure 资源管理器管理的资源类型的详细信息,请参阅资源提供程序和资源类型。
获取存储帐户的帐户类型、位置或复制 SKU
帐户类型、位置和复制 SKU 是存储帐户上的一些可用属性。 可以使用 Azure 门户、PowerShell 或 Azure CLI 来查看这些值。
若要在 Azure 门户中查看存储帐户的帐户类型、位置或复制 SKU,请执行以下步骤:
导航到 Azure 门户中的存储帐户。
在概述页面的“Essentials”分区中找到这些属性
若要使用 PowerShell 查看存储帐户的帐户类型、位置或复制 SKU,请调用 Get-AzStorageAccount 命令以返回存储帐户,然后检查属性:
$account = Get-AzStorageAccount -ResourceGroupName <resource-group> -Name <storage-account>
$account.Location
$account.Sku
$account.Kind
若要使用 PowerShell 查看存储帐户的帐户类型、位置或复制 SKU,请调用 az storage account show 命令并查询属性:
az storage account show \
--name <storage-account> \
--resource-group <resource-group> \
--query '[location,sku,kind]' \
--output tsv
获取存储帐户的服务终结点
存储帐户的服务终结点为 Azure 存储中的任何 Blob、队列、表或文件对象提供基 URL。 使用此基 URL 为任何给定资源构造地址。
若要获取 Azure 门户中存储帐户的服务终结点,请执行以下步骤:
导航到 Azure 门户中的存储帐户。
在“设置”部分中,找到“终结点”设置。
在“终结点”页上,你将看到每个 Azure 存储服务的服务终结点以及资源 ID。
如果存储帐户是异地复制的,则辅助终结点也将在此页上显示。
若要使用 PowerShell 获取存储帐户的服务终结点,请调用 Get-AzStorageAccount 并返回 PrimaryEndpoints
属性。 如果存储帐户是异地复制的,则 SecondaryEndpoints
属性将返回辅助终结点。
(Get-AzStorageAccount -ResourceGroupName $rgName -Name $accountName).PrimaryEndpoints
(Get-AzStorageAccount -ResourceGroupName $rgName -Name $accountName).SecondaryEndpoints
若要使用 Azure CLI 获取存储帐户的服务终结点,请调用 az storage account show 并返回 primaryEndpoints
属性。 如果存储帐户是异地复制的,则 secondaryEndpoints
属性将返回辅助终结点。
az storage account show \
--resource-group <resource-group> \
--name <account-name> \
--query '[primaryEndpoints, secondaryEndpoints]'
获取存储帐户的连接字符串
可以使用连接字符串通过帐户访问密钥(共享密钥授权)来授权访问 Azure 存储。 若要详细了解连接字符串,请参阅配置 Azure 存储连接字符串。
重要
存储帐户访问密钥类似于存储帐户的根密码。 始终要小心保护访问密钥。 使用 Azure 密钥保管库安全地管理和轮换密钥。 避免将访问密钥分发给其他用户、对其进行硬编码或将其以纯文本形式保存在其他人可以访问的任何位置。 如果你认为访问密钥可能已泄露,请轮换密钥。
Azure 建议使用 Microsoft Entra ID 而不是使用帐户密钥(共享密钥授权)来为针对 blob、文件和队列数据的请求授权。 与共享密钥授权相比,使用 Microsoft Entra ID 进行授权提供了更高的安全性和易用性。 有关详细信息,请参阅授权访问 Azure 存储中的数据或授权访问 Azure 门户中的文件数据。
若要在 Azure 门户中获取连接字符串,请执行以下步骤:
- 导航到 Azure 门户中的存储帐户。
- 在“安全 + 网络 ”部分中,找到“访问密钥”设置。
- 若要显示帐户密钥和关联的连接字符串,请选择页面顶部的“显示密钥”按钮。
- 若要将连接字符串复制到剪贴板,请选择连接字符串右侧的“复制”按钮。
若要使用 PowerShell 获取连接字符串,请先获取 StorageAccountContext
对象,然后检索 ConnectionString
属性。
$rgName = "<resource-group>"
$accountName = "storagesamplesdnszone2"
(Get-AzStorageAccount -ResourceGroupName <resource-group> -Name <storage-account>).Context.ConnectionString
获取存储帐户的帐户访问密钥的创建时间
如果存储帐户的一个或两个帐户访问密钥的 keyCreationTime 属性为 null,则需要先轮换密钥,然后才能配置密钥到期策略或 SAS 到期策略。 可使用 Azure 门户、PowerShell 或 Azure CLI 检查存储帐户的 keyCreationTime。
若要在 Azure 门户中显示存储帐户的帐户访问密钥的创建时间,请执行以下步骤:
导航到 Azure 门户中的存储帐户。
在“概述”页面的“Essentials”分区,选择“JSON 视图”链接。
在“资源 JSON”页面上,选择最新的“API 版本”。
在 JSON 中的“属性”下,将看到 key1 和 key2 的 keyCreationTime。
要使用 PowerShell 返回存储帐户的帐户访问密钥的创建时间,请确保已安装 Az.Storage 模块。 接下来,调用 Get-AzStorageAccount 命令获取 keyCreationTime 属性,其中包括两个密钥的创建时间。 在下面的示例代码中,我们获取两个密钥的 keyCreationTime 并测试每个值是否为 null:
$rgName = <resource-group>
$accountName = <storage-account>
# Get the keyCreationTime property of the storage account
$keyCreationTime = (Get-AzStorageAccount -ResourceGroupName $rgName -Name $accountName).keyCreationTime
# Display the value for both keys
$keyCreationTime
# Check both properties for null values
Write-Host 'keyCreationTime.key1 is null = ' ($keyCreationTime.key1 -eq $null)
Write-Host 'keyCreationTime.key2 is null = ' ($keyCreationTime.key2 -eq $null)
要使用 Azure CLI 返回存储帐户的帐户访问密钥的创建时间,请调用 az storage account show 命令并查询 keyCreationTime:
az storage account show \
--name <storage-account> \
--resource-group <resource-group> \
--query keyCreationTime
还可通过在 REST API 中调用“存储帐户 - 获取属性”操作来获取存储帐户的 keyCreationTime。
后续步骤