You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用PowerShell或Azure CLI检索Azure存储表所有记录

我来帮你梳理下用Azure CLI和PowerShell获取Azure存储表所有记录的方法,结合你已经在做的指标查询场景来展开:

使用Azure CLI检索存储表所有记录

你已经在使用az storage entity query命令,要获取某张表的所有记录,其实只需要去掉--filter参数即可。不过要注意:如果表中记录较多,Azure CLI会返回分页结果,需要通过--marker参数循环获取直到没有更多数据。

下面是完整的脚本示例,包括处理分页的逻辑,也可以轻松修改回你需要的过滤条件:

$connection_string = "你的存储账户连接字符串"
$table = "目标表名"

# 初始化标记,用于分页
$next_marker = $null

do {
    # 执行查询,带标记参数(首次为null)
    if ($next_marker) {
        $result = az storage entity query --table-name $table --connection-string $connection_string --accept "none" --marker $next_marker | ConvertFrom-Json
    } else {
        $result = az storage entity query --table-name $table --connection-string $connection_string --accept "none" | ConvertFrom-Json
    }

    # 处理当前页的记录(比如输出或保存)
    Write-Host "当前页获取到 $($result.value.Count) 条记录"
    $result.value | ForEach-Object {
        # 这里可以添加你的业务逻辑,比如提取指标值
        Write-Host "CounterName: $($_.properties.CounterName), Value: $($_.properties.CounterValue)"
    }

    # 更新下一页的标记
    $next_marker = $result.nextMarker
} while ($next_marker)

如果要保留你原来的过滤条件,只需要把--filter参数加回去就行,比如:

--filter "CounterName eq '\Memory\PercentUsedMemory' or CounterName eq '\NetworkInterface\BytesReceived' or CounterName eq '\NetworkInterface\BytesTransmitted' or CounterName eq '\Processor\PercentProcessorTime'"
使用PowerShell检索存储表所有记录

如果你想用原生PowerShell(依赖Az.Storage模块),可以用Get-AzStorageTableEntity命令,操作更贴合PowerShell生态:

首先确保已经安装并导入模块:

Install-Module -Name Az.Storage -Force -AllowClobber
Import-Module Az.Storage

然后执行查询,支持一次性获取所有记录(用-All参数)或者分页:

$storageAccountName = "你的存储账户名"
$tableName = "目标表名"
$resourceGroupName = "你的资源组名"

# 获取存储账户上下文
$ctx = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName).Context

# 获取表的所有记录
$allEntities = Get-AzStorageTableEntity -TableName $tableName -Context $ctx -All

# 处理记录
$allEntities | ForEach-Object {
    Write-Host "CounterName: $($_.CounterName), Value: $($_.CounterValue)"
}

如果需要过滤特定指标,添加-Filter参数即可:

$filter = "CounterName eq '\Memory\PercentUsedMemory' or CounterName eq '\NetworkInterface\BytesReceived' or CounterName eq '\NetworkInterface\BytesTransmitted' or CounterName eq '\Processor\PercentProcessorTime'"
$filteredEntities = Get-AzStorageTableEntity -TableName $tableName -Context $ctx -Filter $filter -All

小提示

  • 不管用哪种方式,确保你的账户有Storage Table Data Reader权限,否则会出现访问拒绝错误。
  • 对于超大型表,建议分批次获取(比如按PartitionKey过滤),避免一次性查询超时。

内容的提问来源于stack exchange,提问作者Reza Amya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:15:39