使用Azure PowerShell获取azure表的分区中的行数

时间:2017-06-06 09:02:39

标签: azure-powershell azure-table-storage

我想获得分区中的行数。我有获取行总数的代码。如何更改它以获取特定分区的计数。此外,我收到警告,要求获取所有行的计数,而不是获取PowerShell窗口的计数。有没有关于此的文件?

 function GetTable($connectionString, $tableName)
{
    $context = New-AzureStorageContext -ConnectionString $connectionString
    $azureStorageTable = Get-AzureStorageTable $tableName -Context $context
    $azureStorageTable
}

function GetTableCount($table)
{
    #Create a table query.
    $query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery

    #Define columns to select. 
    $list = New-Object System.Collections.Generic.List[string] 
    $list.Add("PartitionKey")

    #Set query details.
    $query.SelectColumns = $list

    #Execute the query.
    $entities = $table.CloudTable.ExecuteQuery($query)
    ($entities | measure).Count
}

$connectionString = "xyz"
$table = GetTable $connectionString SystemAudit
GetTableCount $table

1 个答案:

答案 0 :(得分:0)

  

如何更改它以获取特定分区的计数

您可以使用一个函数Get-AzureStorageTableRowByPartitionKey,以下是示例代码

function GetTable($connectionString, $tableName)
{
    $context = New-AzureStorageContext -ConnectionString $connectionString
    $azureStorageTable = Get-AzureStorageTable $tableName -Context $context
    $azureStorageTable
}

function GetTableCount($table)
{

    $list = Get-AzureStorageTableRowByPartitionKey -table $table –partitionKey “storage” | measure
    $list.Count
}
Import-Module AzureRmStorageTable
$connectionString = xyz"
$table = GetTable $connectionString <yourTableName>
GetTableCount $table

您可以了解有关this blog

的更多信息