我正在尝试使用PowerShell上传azure表行,我收到以下错误。这可能是由于错误的Azure存储PowerShell模块造成的吗?我使用的是Azure.Storage 4.0.2模块。
以下是代码:
# 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
}
}
}
}
}
以下是我收到的例外情况:
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
我已经通过几个关于如何排除故障的在线资源,但我没有得到任何解决方案。
答案 0 :(得分:0)
我使用fiddler捕获我的代码添加实体请求。然后我可以获得属性名称无效的详细信息。
因此,请尝试使用以下代码更改属性名称。
$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
有关azure表属性名称的更多信息,请参阅此document。
poperty名称是区分大小写的字符串,最多255个字符。属性名称应遵循C# identifiers的命名规则。
测试结果: