找不到 "Execute" 和参数计数的重载:“1”。无法插入 Azure 存储 table
Cannot find an overload for "Execute" and the argument count: "1". unable to insert into azure storage table
我有一个 powershell 脚本可以将数据上传到 azure 存储 table。 Powershell 脚本如下所示:
$StorageAccountName = "xxx"
$StorageAccountKey = "xxxxx"
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tableName = "ProvisioningRecord"
$table = Get-AzStorageTable –Name $tableName -Context $ctx
Add-Entity -table $table -partitionKey abc -rowKey xyz
function Add-Entity {
[CmdletBinding()]
param(
$table,
[String]$partitionKey,
[String]$rowKey
)
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" -ArgumentList $partitionKey, $rowKey
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
}
我收到错误:
Cannot find an overload for "Execute" and the argument count: "1".
At line:1 char:1
+ $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
在此 link 之后:https://www.catapultsystems.com/blogs/azure-storage-powershell-error-cannot-find-an-overload/ 我添加了
$assemblySN = $table.CloudTable.GetType().Assembly.FullName
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
$result = $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::InsertOrReplace(`$entity)"))
它给我一个错误:
New-Object : Cannot find type [Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,Microsoft.Azure.Cosmos.Table, Version=0.10.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]:
verify that the assembly containing this type is loaded.
At line:1 char:11
+ $entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
但经过上述修改(添加 $assemblySN)的相同代码适用于 Powershell 版本 5.1.17134.590。相同的脚本在 Powershell 版本 5.1.17763.316 中不起作用。
有人可以帮我解决这个问题吗?
您使用哪个版本的 Az.Storage 模块? (运行 Get-module 检查)。
从 Az.Storage 1.1.0 开始,table 使用 Microsoft.Azure.Cosmos.Table SDK 进行管理。 (因为新的存储客户端库不再支持 table。)
因此 Azure Table 对象的命名空间从 "Microsoft.WindowsAzure.Storage.Table" 更改为 "Microsoft.Azure.Cosmos.Table"。您需要相应地更改脚本中的命名空间。
我有一个 powershell 脚本可以将数据上传到 azure 存储 table。 Powershell 脚本如下所示:
$StorageAccountName = "xxx"
$StorageAccountKey = "xxxxx"
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tableName = "ProvisioningRecord"
$table = Get-AzStorageTable –Name $tableName -Context $ctx
Add-Entity -table $table -partitionKey abc -rowKey xyz
function Add-Entity {
[CmdletBinding()]
param(
$table,
[String]$partitionKey,
[String]$rowKey
)
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" -ArgumentList $partitionKey, $rowKey
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
}
我收到错误:
Cannot find an overload for "Execute" and the argument count: "1".
At line:1 char:1
+ $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
在此 link 之后:https://www.catapultsystems.com/blogs/azure-storage-powershell-error-cannot-find-an-overload/ 我添加了
$assemblySN = $table.CloudTable.GetType().Assembly.FullName
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
$result = $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::InsertOrReplace(`$entity)"))
它给我一个错误:
New-Object : Cannot find type [Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,Microsoft.Azure.Cosmos.Table, Version=0.10.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]:
verify that the assembly containing this type is loaded.
At line:1 char:11
+ $entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
但经过上述修改(添加 $assemblySN)的相同代码适用于 Powershell 版本 5.1.17134.590。相同的脚本在 Powershell 版本 5.1.17763.316 中不起作用。
有人可以帮我解决这个问题吗?
您使用哪个版本的 Az.Storage 模块? (运行 Get-module 检查)。
从 Az.Storage 1.1.0 开始,table 使用 Microsoft.Azure.Cosmos.Table SDK 进行管理。 (因为新的存储客户端库不再支持 table。)
因此 Azure Table 对象的命名空间从 "Microsoft.WindowsAzure.Storage.Table" 更改为 "Microsoft.Azure.Cosmos.Table"。您需要相应地更改脚本中的命名空间。