Working with Azure Storage Tables from PowerShell


Hello, AzureRmStorageTable got a major update, now it is v2.0 and you can find a newer version of this post at my new blog: https://paulomarquesc.github.io/working-with-azure-storage-tables-from-powershell

Comments (25)

  1. Felix Bodmer says:

    Thanks, this is excellent and desperately needed. Any plans to add this to the Azure PowerShell module?

    1. Hi Felix,

      I’m talking to the product group but no plans so far.

      Regards

      Paulo

  2. J Metz says:

    Hi Paulo,
    I’m very excited to start using this module, but I get this message when I try to import the module after installation.. I have the latest Azure Powershell module installed. Any ideas?
    import-module : Azure PowerShell module must be installed in order to expose Microsoft.WindowsAzure.Storage.dll file.
    At line:1 char:1
    + import-module AzureRMStorageTable

    1. Hi J Metz,

      Glad to hear that it will help you :-), now, related to your issue, when working from a regular PowerShell command prompt session or scheduled task the module looks for two Dlls, Microsoft.WindowsAzure.Storage.dll and Microsoft.WindowsAzure.Commands.Common.Storage.dll at “${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Storage” path, which is the default installation path of the Azure PowerShell module (http://aka.ms/webpi-azps).

      Can you please check if you have these two Dlls at that folder? Also, please execute “get-module -name Azure -ListAvailable” and check if the version you have is 3.4.0.

      Not related to your question/issue, but I just found a bug on 1.0.0.5 version and fixed on 1.0.0.6 version, please update your local module with this new version as well.

      Regards

      Paulo

      1. J Metz says:

        Thanks Paulo, I have everything working now!!

        One thing I am still a bit confused about is the fact that you reference the SDK path vs the default PSGet\Install-Module target folder (C:\Program Files\WindowsPowershell). Since there are two “correct ways” of acquire these modules\dll’s, do you think you might be able to check both the SDK and PSGet paths for the proper dll’s during your validation checks? I had a few discussions with our PFE and people in the Powershell product group to try to better understand these two acquisition methods, so I think this might be the way to go. Let me know what you think and thanks again for this great module. :)

        1. Yep, I completely forgot about the module installed via Install-Module, I always use the web platform installer. I’ll add support for those folders as well.

          1. J Metz says:

            Thank you sir. :D

  3. Charles says:

    Excellent. Thanks Paulo. Tao Yang also wrote a module to do pretty much the same. Thanks a lot guys.
    http://blog.tyang.org/2016/11/30/powershell-module-for-managing-azure-table-storage-entities/

  4. Joseph Truong says:

    Thanks for the article, I was just wondering is there a way to modify an existing row such that you can add an attribute to it. Currently when i try to modify a row with an attribute that does not exist, I get an exception saying The property ‘something’ cannot be found on this object.

  5. William Lee says:

    A guy much wiser then myself showed me how to upload the .zip without the .dlls in azure automation … and without all the load .dlls

    At the top of the psm1 put this:

    #Requires -Modules AzureRM.Profile, AzureRM.Storage, AzureRM.Resources, Azure.Storage

    Azure will load the modules that you already installed, just make sure the modules are installed in azure automation module list.

    Also place all the files in a folder with the same name as the psm1 then zip the folder.

    1. Hi William,

      That’s a good point, thanks for the reminder, I just updated the module to use it instead.
      For those interested on more details about the #Requires, please refer to https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_requires.

      Regards

      Paulo

  6. Anton Boyko says:

    Hi!

    Very cool module, it looks like a very nice, but missing part, of Azure PS Module from azure.com website. It is so cool, that I even want to add my contribution to it. I have added a support for using empty string values for partition keys and row keys. You can find my pull request here https://github.com/paulomarquesc/AzureRmStorageTable/pull/3.

    1. Hi Anton,

      Thank you for the great contribution, I just approved the merge and published a new version in the PowerShell Gallery.

      Regards

      Paulo

  7. Peter Embleton says:

    this looks like exactly what i need, i am particaullary interested in using this from an automation account.
    Unfortunately i cant seem to get it to work, even using the examples out of this post;

    Add-StorageTableRow -table $table -partitionKey $partitionKey -rowKey ([guid]::NewGuid().tostring()) -property @{“computerName”=”COMP03″;”osVersion”=”Windows XP”;”status”=”NeedsOsUpgrade”}
    Unable to find type [Microsoft.WindowsAzure.Storage.Table.TableOperation,Microsoft.WindowsAzure.Storage, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35].
    At C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.10\AzureRmStorageTableCoreHelper.psm1:219 char:32
    + … ble.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation, Mic …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (Microsoft.Windo…1bf3856ad364e35:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

    any clues as to what i am missing?
    thanks

    1. Peter Embleton says:

      this error went away after i installed azure storage explorer, there might be a dependency there

      1. Hi Peter, please see my last comment, bug was fixed last night with a new version of the module.

    2. Hi Peter,

      I had a issue with 1.0.0.10 version, a bug in the Add-StorageTableRow that I fixed yesterday on 1.0.0.11 version. The storage explorer may have been a workaround but I officially fixed yesterday :-).

      BTW, after you build your automation, if you can share your use-case for that, it will be cool.

      Regards

      Paulo

  8. GeneLaisne says:

    In the Updating an entry example, the line:
    $person | Update-AzureStorageTableRow -table $table
    should be:
    $computer | Update-AzureStorageTableRow -table $table

    1. Hi Gene,

      Thanks, I just updated it.

      Regards

      Paulo

  9. Adam Robinson says:

    Any plans to support PowerShell Core?

    1. Hi Adam,

      Not yet, but will investigate the dependencies to check if it is feasible at this time.

      Regards

      Paulo

  10. Matt Wardle says:

    Hey, When running Add-StorageTableRow, i get the below error:

    New-Object : Cannot find type [Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity, Microsoft.WindowsAzure.Storage, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=#############]: verify that the assembly containing this type is loaded.

    I have PS 5.1, Azure Powershell Module and Storage Explorer installed.

    Any help would be appreciated,

    Thanks

    Matt

    1. Hi Matt,

      I could not reproduce your issue, in order to make this better to troubleshoot, can you please open an issue at https://github.com/paulomarquesc/AzureRmStorageTable/issues ? That’s where the project is hosted and it is better suited for tracking issues that here.

      This module does not have the requirement for Azure Storage Explorer, of course it can be installed for visualizing your data better but it is not a requirement. If working with Azure Storage Tables (not Cosmos DB because there are other requirements there) the following modules are the required ones (version 4 and up):

      AzureRM.Profile
      AzureRM.Storage
      AzureRM.Resources
      Azure.Storage

      Those are the only requirements.

      When opening the issue can you please provide the following information:

      1) Output of $psversiontable from Powershell
      2) Output from “get-module -name *azure* -listavailable”
      3) Exact reproduction steps

      Regards

      Paulo

  11. Eric V says:

    Great article. Thanks. I’m not a hardcore programmer, so I’m sure this is a simple q. Why is this failing?

    # ..code above, set up my AzureRMStore account & create table, get context (works fine)
    # Get stuff to shove into Azure Table Store for testing.
    $x = Get-WMIObject Win32_Bios
    # From Stackoverflow -> Convert PSObject, all properties into Hashtable, $h
    $x.psobject.properties | ForEach-Object -begin {$h=@{}} -process {$h.”$($_.Name)” = $_.Value} -end {$h}
    # Shove stuff into Azure Table Store
    Add-StorageTableRow -table $table -partitionKey $PartitionKey -rowKey ([guid]::NewGuid().tostring()) -property $h

    I get “Cannot find an overload for “Add” and the argument count: “2”, AzureRmStorageTable\1.0.0.21\AzureRmStorageTableCoreHelper.psm1:260 char:4″

    1. Hi Eric,

      Can you please open an issue at https://github.com/paulomarquesc/AzureRmStorageTable/issues?

      That’s where the project is hosted and it is better suited for tracking issues. I believe that you’re missing a requirement, this module depends on version 4 and up of the following modules:

      AzureRM.Profile
      AzureRM.Storage
      AzureRM.Resources
      Azure.Storage

      When opening the issue can you please provide the following information of the machine you are trying to execute the module:

      1) Output of $psversiontable from Powershell
      2) Output from “get-module -name *azure* -listavailable”
      3) Exact reproduction steps

      While you do this, can you also please, instead of getting the storage, context object and the table reference from the Powershell cmdlets provided by default, can you please try using a cmdlet from my module called Get-AzureStorageTabletable? Follows a code sample, so you can replace all initial steps with this single command line:

      $resourceGroup = “myResourceGroup”
      $storageAccount = “mystorageaccount”
      $tableName = “table01”
      $table = Get-AzureStorageTableTable -resourceGroup $resourceGroup -tableName $tableName -storageAccountName $storageAccount

      The reasoning for this that sometimes you may have more than one DLL version in your system and using my cmdlet makes sure you use the correct version that will expose the “Add” method.

      Regards

      Paulo

Skip to main content