/aztablestorage

PowerShell module for performing CRUD operations against Azure Table Storage

Primary LanguagePowerShell

Azure Table Storage CRUD operations with PowerShell

This PowerShell module encapsulates basic CRUD operations against Azure Table Storage. The module uses the REST API to perform these activities. This module has been used in several projects to store and manipulate data in automation scripts against Azure Tables.

Usage

  • Get the AZTableModule.psm1 and store it to your desired location
  • Get your Azure Storage name and key. You will need it in the script

Examples

Initializing the module

$storage = "addYourStorageNameHere"
$key = "addYourStorageSecretKeyHere"

Import-Module AZTableModule.psm1 -ArgumentList $storage, $key

Creating a new table

New-AzTable "sampletable"

Add a new entry to your table

  • Dates must be older or equal than "1901-01-01"
  • Replaces the entry if the unique key and partitionkey matches
$birthDate = (Get-date -date "1983-01-02")
$patrick = @{
    PartitionKey = 'yourPartitionName'
    RowKey = 'yourUniqueRowKeyPatrick'
    "birthDate@odata.type"="Edm.DateTime"
    birthDate = $birthDate.toString("yyyy-MM-ddT00:00:00.000Z")
    name = "Patrick"
    lastname = "Lamber"
}
Add-AzTableEntry -table "sampletable" -partitionKey $patrick.PartitionKey -rowKey $patrick.RowKey -entity $patrick

Create a new entry or merge it with an existing one

$birthDate = (Get-date -date "1986-10-19")
$rene = @{<br />
    PartitionKey = 'yourPartitionName'
    RowKey = 'yourUniqueRowKeyRene'
    "birthDate@odata.type"="Edm.DateTime"
    birthDate = $birthDate.toString("yyyy-MM-ddT00:00:00.000Z")
    name = "Rene'"
    lastname = "Lamber
}
Merge-AzTableEntry -table "sampletable" -partitionKey $rene.PartitionKey -rowKey $rene.RowKey -entity $rene

Return a single entry

$patrickFromTheCloud = Get-AzTableEntry -table "sampletable" -partitionKey $patrick.PartitionKey -rowKey $patrick.RowKey

Update an individual field of an existing entry

$patrickFromTheCloud = Get-AzTableEntry -table "sampletable" -partitionKey $patrick.PartitionKey -rowKey $patrick.RowKey
$patrickFromTheCloud.name = "Patrick has been updated"
Merge-AzTableEntry -table "sampletable" -partitionKey $patrickFromTheCloud.PartitionKey -rowKey $patrickFromTheCloud.RowKey -entity $patrickFromTheCloud

Get all entries

$entries = Get-AzTableEntries -table "sampletable"

Select individual fields from the table

$entriesWithSomeProperties = Get-AzTableEntries -table "sampletable" -select "RowKey,PartitionKey,name"

Filter entries

$filteredEntries = Get-AzTableEntries -table "sampletable" -filter "name eq 'Patrick'"

Delete an entry

Remove-AzTableEntry -table "sampletable" -partitionKey $rene.PartitionKey -rowKey $rene.RowKey

Delete a table

Remove-AzTable -table "sampletable"