I was happy to find the New-AzureStorageTable cmdlet, but I haven't figured out how to insert a new row in the table.
I found the following code on the internet, but the CloudTable.Execute seems to fail.
It needs three arguments as described in http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.table.cloudtable.execute(v=azure.10).aspx but I cannot figure out how to call the method.
Any ideas are appreciated!
function InsertRow($table, [String]$partitionKey, [String]$rowKey, [int]$intValue)
{
$entity = New-Object "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" $partitionKey, $rowKey
$entity.Properties.Add("IntValue", $intValue)
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
}
$StorageAccountName = "MyAccountName"
$StorageAccountKey = "MyAccountKey"
$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$table = New-AzureStorageTable test -Context $context
for ($p = 1; $p -le 10; $p++)
{
for ($r = 1; $r -le 10; $r++)
{
InsertRow $table "P$p" "R$r" $r
}
}
UPDATE
As suggested below you have to use Get-AzureStorageTable to check if the table already exists first.
$tablename = "test"
$table = Get-AzureStorageTable $tablename -Context $context -ErrorAction Ignore
if ($table -eq $null)
{
New-AzureStorageTable $tablename -Context $context
}