Azure RM Storage Tables PowerShell module now includes support for Cosmos DB Tables


Hi Everyone,

This blog is an addendum to the Working with Azure Storage Tables from PowerShell post, to talk about the new capability of the Azure Rm Storage Tables PowerShell module that now supports Azure Cosmos DB Tables, for more information on Azure Cosmos DB, please refer to Azure Cosmos DB Documentation.

This post will show how to add this support, notice that Cosmos DB Table API is in preview therefore this module is not well suited at this moment for production workloads and is very prone to frequently changes.

In order to use it against Azure Cosmos DB, the first requirement is that your Azure Cosmos DB is created with support for Table API as shown below:



Although I added support to the module, it does not come with necessary required DLLs to access Azure Cosmos DB tables, in order to add that support to your local copy of the module, please follow these steps:

  1. Make sure you followed all the steps to install the module outlined here (same link mentioned in the first paragraph of this post).
  2. Open an elevated PowerShell command prompt
  3. Change folder to the folder where you installed the module, e.g.

    C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\

    Important: Please, make you need to make sure that it is the same folder where the AzureRmStorageTable.psd1 and AzureRmStorageTableCoreHelper.psm1 files are located.

  4. Download the file from GitHub and save it with the same name to that folder. You can use the following code snippet to download the file from PowerShell:

    $filename = "$pwd\Install-CosmosDbInstallPreReqs.ps1"
    $webclient = New-Object System.Net.WebClient
    $url = ""

  5. Execute the script:


  6. This will add the following DLLs to your module folder, without these DLLs the module won’t work with Azure Cosmos DB


    Notice that since this is preview API, these files are prone to change more frequently than the normal and changes to the script may need to be done in order to add them, specially the versions of the nuget packages.

After you add the necessary assemblies the operation of the cmdlets are exactly the same, with a small difference that the Azure Cosmos DB table API at this moment has a bug related to empty strings for partition and row keys at this moment so there is a test that is performed when trying to use empty strings with it and the following error will show up:

Cosmos DB table API does not accept empty partition or row keys when using CloudTable.Execute operation, because of this we are disabling this capability in this module and it will not proceed.
At C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\AzureRmStorageTableCoreHelper.psm1:32 char:9
+         Throw $cosmosDBEmptyKeysErrorMessage
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Cosmos DB table...ll not proceed.:String) [], RuntimeException
    + FullyQualifiedErrorId : Cosmos DB table API does not accept empty partition or row keys when using CloudTable.Execute operation, because of this we are disabling this capability in this module and it will not proceed.


Another change performed in the module is that now there is a cmdlet called Get-AzureStorageTableTable and it gets the reference for the table you want to work with, independently if it is Azure Storage Table or Azure Cosmos DB table.  The examples below shows how to get each table:

Azure Storage Table

$resourceGroup = "myResourceGroup"
$storageAccount = "mystorageaccount"
$tableName = "table01"
$table = Get-AzureStorageTabletable -resourceGroup $resourceGroup -tableName $tableName -storageAccountName $storageAccount


Azure Cosmos DB Table

$resourceGroup = "myResourceGroup"
$cosmosDbAccountName = "myCosmosDb"
$tableName = "table01"
$table01 = Get-AzureStorageTabletable -resourceGroup $resourceGroup -tableName $tableName -cosmosDbAccount $cosmosDbAccountName

Note: Starting with the module version the parameter databaseName became an alias of the parameter cosmosDbAccount for backward compatibility.


From this point, all cmdlets described in my previous related article applies and can be found here.

Known Issues

  1. “Id” as one of the entity properties will cause an error.

    As of today, the key value “ID” cannot be a name of an entity property, if you try to use it as one of the properties, similar to the following example, it will fail:

    Add-StorageTableRow -table $table01 -partitionKey $partitionKey1 -rowKey "CA" -property @{"username"="Chris";"id"="1"} 

    Exception calling "Execute" with "1" argument(s): "Additional text found in JSON string after finishing deserializing object."
    At line:1 char:1
    + $table01.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : StorageException


That’s it for this post, stay tuned for updates.


For  more information please refer to:

Azure Rm Storage Table PowerShell module source

Module at PowerShell Gallery

Frequently asked questions about Azure Cosmos DB

Azure Cosmos DB: Build a .NET application using the Table API




Comments (0)

Skip to main content