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:
- Make sure you followed all the steps to install the module outlined here (same link mentioned in the first paragraph of this post).
- Open an elevated PowerShell command prompt
- Change folder to the root folder of the module
- Download the file https://raw.githubusercontent.com/paulomarquesc/AzureRmStorageTable/master/Install-CosmosDbInstallPreReqs.ps1 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:
- Execute the script:
- 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
Azure Cosmos DB Table
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