mansos
mansos

Reputation: 57

Azure Table on Azure Automation

We're trying to perform Azure Table data operations from Azure Automation. Currently using Powershell 7.1 and have installed module AzTable. The following works:

$azureContext = (Connect-AzAccount -Identity).context
$azureContext = Set-AzContext -SubscriptionName $azureContext.Subscription -DefaultProfile $azureContext
$storageContext = New-AzStorageContext -StorageAccountName $storageAccount

$table = (Get-AzStorageTable -Name $tableName -Context $storageContext).CloudTable

But when trying a data operation such as

Add-AzTableRow -Table $table -partitionKey "1" -rowKey ("key1") -property @{"prop1"="test1";"prop2"="test2"}

We end up with exceptions such as

MethodInvocationException: C:\ModulesV2\User\AzTable\AzureRmStorageTableCoreHelper.psm1:266 Line | 266 | … return ($Table.Execute([Microsoft.Azure.Cosmos.Table.TableOperat … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Exception calling "Execute" with "1" argument(s): "The specified resource does not exist."

We will try to use $table.ExecuteBatch() but that also fails. We're missing some dependencies but can't figure out which. This is a vanilla Azure Automation account we just created.

Should this be supported?

Upvotes: 0

Views: 857

Answers (1)

SureshBabu
SureshBabu

Reputation: 474

Exception calling "Execute" with "1" argument(s): "The specified resource does not exist."

As mentioned in error the Add-AzTableRow is not getting the table which you are specifying

As mentioned in Microsoft Document,

Using the CloudTable property is mandatory when working with table data via the AzTable PowerShell module.

  • While using AzTable to work on a table, it is mandatory to use CloudTable property.

  • The .Net methods accessible for handling table data from PowerShell are exposed through the CloudTable property.

Example code:

$cloudTable = $storageTable.CloudTable

Reference:

https://learn.microsoft.com/en-us/azure/storage/tables/table-storage-how-to-use-powershell?toc=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Ftables%2Ftoc.json&bc=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fazure%2Fbread%2Ftoc.json#reference-the-cloudtable-property-of-a-specific-table

Upvotes: 0

Related Questions