priya
priya

Reputation: 163

Get count of rows in a partition of an azure table using Azure PowerShell

I would like to get count of rows in a partition. I have the code for getting the total count of rows. How can I alter it to get count for a particular partition. Also I am getting warning for fetching count of all rows and not getting the count on powershell window. Is there any documentation on this?

 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

Upvotes: 0

Views: 1015

Answers (1)

Hayley244
Hayley244

Reputation: 71

How can I alter it to get count for a particular partition

There is a function Get-AzureStorageTableRowByPartitionKey you could use, and the following is the sample code

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

You can know more information on this blog

Upvotes: 0

Related Questions