I am trying to upload azure table row using PowerShell and I am receiving the below error. Could this be due to wrong Azure Storage powershell modules? I am using Azure.Storage 4.0.2 module.
Below is the Code:
# Getting all the resource group
$resource_group_list = Get-AzureRmResourceGroup
# Iterating through the resource group
foreach($resource_group_list_iterator in $resource_group_list){
# Since the solution applies for virtual machines,
# obtain the list of virtual machines for the resource group
$virtual_machine_list = get-azurermvm -ResourceGroupName $resource_group_list_iterator.ResourceGroupName
# Proceed only when resource group contains virtual machines
if(!($virtual_machine_list -eq $null)){
# Iterate through the virtual machine list
foreach($virtual_machine_list_iterator in $virtual_machine_list){
# Creat an unique ID by concatinating 'Resource Group name' and 'Virtual Machine name'
$unique_id = $resource_group_list_iterator.ResourceGroupName + $virtual_machine_list_iterator.name
#Write-Host $unique_id
$tag_list = $virtual_machine_list_iterator.Tags
$tag_list.GetEnumerator() | foreach {
#write-host $_.key
#Write-Host $_.value
#write-host ""
$partitionKey1 = $unique_id
if($_.key -eq 'owner' -and $_.value -eq 'ibm') {
#write-host "true"
$virtual_machine_name = $virtual_machine_list_iterator.Name.ToString()
$virtual_machine_resource_group_name = $resource_group_list_iterator.ResourceGroupName.ToString()
$virtual_machine_location = $virtual_machine_list_iterator.Location.ToString()
$virtual_machine_size = $virtual_machine_list_iterator.HardwareProfile.VmSize.ToString()
$virtual_machine_operating_system = $virtual_machine_list_iterator.StorageProfile.ImageReference.Offer.ToString()
$hash = @{}
#$hash.add('currentDate', $current_date)
$hash.Add('VM Name','VM')
$hash.Add('Resource Group',$virtual_machine_resource_group_name)
$hash.add('Location',$virtual_machine_location)
$hash.add('VM Size',$virtual_machine_size)
$hash.add('Operating System',$virtual_machine_operating_system)
Add-StorageTableRow -table $azure_table_object -partitionKey ("CA") -rowKey $unique_id -property $hash
}
}
}
}
}
Below is the exception that I received:
Exception calling "Execute" with "1" argument(s): "The remote server returned an error: (400)
Bad Request."
At C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.21\AzureRmStorageTableCor
eHelper.psm1:267 char:16
+ ... return ($table.CloudTable.Execute((invoke-expression "[Microsoft ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : StorageException
I have gone thru few online resources on how to troubleshoot, but I did not get any solution.
I use the fiddler to catch adding entity request on my side with your code. Then I could get the detail information that property name is invalid.
So please have a try to change the property name with following code.
$hash.Add('VM_Name','VM') #VM Name is invalid
$hash.Add('Resource_Group',$virtual_machine_resource_group_name) #Resource Group is invalid
$hash.add('Location',$virtual_machine_location)
$hash.add('VM_Size',$virtual_machine_size) #VM size is invalid
$hash.add('Operating_System',"windows")
Add-StorageTableRow -table $table -partitionKey ("CA") -rowKey $unique_id -property $hash
For more information about azure table property name please refer to this document.
poperty names are case-sensitive strings up to 255 characters in size. Property names should follow naming rules for C# identifiers.
Test Result: