Azure 找不到“的重载”;“执行机构”;并且参数计数为:“quot;1“;
strong文本找不到“ExecuteQuery”和参数计数“1”的重载。 位于C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.23\AzureRmStorageTableCoreHelper.psm1:369 char:2 +$result=$table.CloudTable.ExecuteQuery($tableQuery) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:NotSpecified:(:)[],MethodException +FullyQualifiedErrorId:MethodCountNotFindBest 找不到“Execute”和参数计数“1”的重载。 位于C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.23\AzureRmStorageTableCoreHelper.psm1:191 char:11 + ... return($table.CloudTable.Execute)((调用表达式“[Microsoft。。。 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:NotSpecified:(:)[],MethodException +FullyQualifiedErrorId:MethodCountNotFindBest 找不到“Execute”和参数计数“1”的重载。 第1行字符:1 +[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,Microsoft.Wi。。。 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:NotSpecified:(:)[],MethodException +FullyQualifiedErrorId:MethodCountNotFindBest 这就是AzureRmStorageTableCoreHelper的外观 需要-模块Azure.Storage、AzureRm.Profile、AzureRm.Storage、AzureRm.Resources 模块功能 函数GetLatestFullAssemblyName { param ( [字符串]$dllName ) } 正在获取最新的Microsoft.WindowsAzure.Storage.dll完整程序集名称 $assemblySN=(GetLatestFullAssemblyName-dllName“Microsoft.WindowsAzure.Storage.dll”).fullname 功能测试AzureStorageTableEmptyKeys { [CmdletBinding()] param ( [string]$partitionKey, [字符串]$rowKey ) } 函数Get AzureStorageTableTable { [CmdletBinding()] param ( [参数(ParameterSetName=“AzureRmTableStorage”,必填=$true)] [字符串]$resourceGroupAzure 找不到“的重载”;“执行机构”;并且参数计数为:“quot;1“;,azure,powershell,azure-table-storage,Azure,Powershell,Azure Table Storage,strong文本找不到“ExecuteQuery”和参数计数“1”的重载。 位于C:\Program Files\WindowsPowerShell\Modules\AzureRmStorageTable\1.0.0.23\AzureRmStorageTableCoreHelper.psm1:369 char:2 +$result=$table.CloudTable.ExecuteQuery($tableQuery) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Parameter(Mandatory=$true)]
[String]$tableName,
[Parameter(ParameterSetName="AzureRmTableStorage",Mandatory=$true)]
[Parameter(ParameterSetName="AzureTableStorage",Mandatory=$true)]
[String]$storageAccountName
)
$nullTableErrorMessage = [string]::Empty
switch ($PSCmdlet.ParameterSetName)
{
"AzureRmTableStorage"
{
$saContext = (Get-AzureRmStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName).Context
$nullTableErrorMessage = "Table $tableName could not be retrieved from Storage Account $storageAccountName on resource group $resourceGroupName"
}
"AzureTableStorage"
{
$saContext = (Get-AzureStorageAccount -StorageAccountName $storageAccountName).Context
$nullTableErrorMessage = "Table $tableName could not be retrieved from Classic Storage Account $storageAccountName"
}
}
[Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageTable]$table = Get-AzureStorageTable -Name $tableName -Context $saContext -ErrorAction SilentlyContinue
# Creating a new table if one does not exist
if ($table -eq $null)
{
[Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageTable]$table = New-AzureStorageTable -Name $tableName -Context $saContext
}
# Checking if there a table got returned
if ($table -eq $null)
{
throw $nullTableErrorMessage
}
# Returns the table object
return [Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageTable]$table
}
函数addStorageTableRow
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$partitionKey,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$rowKey,
[Parameter(Mandatory=$false)]
[hashtable]$property,
[Switch]$UpdateExisting
)
# Creates the table entity with mandatory partitionKey and rowKey arguments
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
# Adding the additional columns to the table entity
foreach ($prop in $property.Keys)
{
if ($prop -ne "TableTimestamp")
{
$entity.Properties.Add($prop, $property.Item($prop))
}
}
if($UpdateExisting)
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insertorreplace(`$entity)")))
}
else
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insert(`$entity)")))
}
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[string]$partitionKey
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition("PartitionKey",`
[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::Equal,$partitionKey)
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$columnName,
[Parameter(ParameterSetName="byString",Mandatory=$true)]
[AllowEmptyString()]
[string]$value,
[Parameter(ParameterSetName="byGuid",Mandatory=$true)]
[guid]$guidValue,
[Parameter(Mandatory=$true)]
[validateSet("Equal","GreaterThan","GreaterThanOrEqual","LessThan" ,"LessThanOrEqual" ,"NotEqual")]
[string]$operator
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
if ($PSCmdlet.ParameterSetName -eq "byString") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$value)
}
if ($PSCmdlet.ParameterSetName -eq "byGuid") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterConditionForGuid($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$guidValue)
}
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$customFilter
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$tableQuery.FilterString = $customFilter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$entity
)
# Only one entity at a time can be updated
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Update operation can happen on only one entity at a time, not in a list/array of entities."
}
$updatedEntity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $entity.PartitionKey, $entity.RowKey
# Iterating over PS Object properties to add to the updated entity
foreach ($prop in $entity.psobject.Properties)
{
if (($prop.name -ne "PartitionKey") -and ($prop.name -ne "RowKey") -and ($prop.name -ne "Timestamp") -and ($prop.name -ne "Etag") -and ($prop.name -ne "TableTimestamp"))
{
$updatedEntity.Properties.Add($prop.name, $prop.Value)
}
}
$updatedEntity.ETag = $entity.Etag
# Updating the dynamic table entity to the table
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Replace(`$updatedEntity)")))
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="byEntityPSObjectObject")]
$entity,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$partitionKey,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$rowKey
)
begin
{
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Delete operation cannot happen on an array of entities, altough you can pipe multiple items."
}
$results = @()
}
process
{
if ($PSCmdlet.ParameterSetName -eq "byEntityPSObjectObject")
{
$partitionKey = $entity.PartitionKey
$rowKey = $entity.RowKey
}
$entityToDelete = invoke-expression "[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN](`$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Retrieve(`$partitionKey,`$rowKey))).Result"
if ($entityToDelete -ne $null)
{
$results += $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Delete(`$entityToDelete)"))
}
}
end
{
return ,$results
}
}
函数Get PSObjectFromEntity
{
#内部功能
#将从表的ExecuteQuery方法输出的实体转换为PowerShell对象数组
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
$entityList
)
$returnObjects = @()
if (-not [string]::IsNullOrEmpty($entityList))
{
foreach ($entity in $entityList)
{
$entityNewObj = New-Object -TypeName psobject
$entity.Properties.Keys | ForEach-Object {Add-Member -InputObject $entityNewObj -Name $_ -Value $entity.Properties[$_].PropertyAsObject -MemberType NoteProperty}
# Adding table entity other attributes
Add-Member -InputObject $entityNewObj -Name "PartitionKey" -Value $entity.PartitionKey -MemberType NoteProperty
Add-Member -InputObject $entityNewObj -Name "RowKey" -Value $entity.RowKey -MemberType NoteProperty
Add-Member -InputObject $entityNewObj -Name "TableTimestamp" -Value $entity.Timestamp -MemberType NoteProperty
Add-Member -InputObject $entityNewObj -Name "Etag" -Value $entity.Etag -MemberType NoteProperty
$returnObjects += $entityNewObj
}
}
return $returnObjects
}
函数Get-AzureStorageTableRowAll
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
)
}
函数Get-AzureStorageTableRowByPartitionKey
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$partitionKey,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$rowKey,
[Parameter(Mandatory=$false)]
[hashtable]$property,
[Switch]$UpdateExisting
)
# Creates the table entity with mandatory partitionKey and rowKey arguments
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
# Adding the additional columns to the table entity
foreach ($prop in $property.Keys)
{
if ($prop -ne "TableTimestamp")
{
$entity.Properties.Add($prop, $property.Item($prop))
}
}
if($UpdateExisting)
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insertorreplace(`$entity)")))
}
else
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insert(`$entity)")))
}
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[string]$partitionKey
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition("PartitionKey",`
[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::Equal,$partitionKey)
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$columnName,
[Parameter(ParameterSetName="byString",Mandatory=$true)]
[AllowEmptyString()]
[string]$value,
[Parameter(ParameterSetName="byGuid",Mandatory=$true)]
[guid]$guidValue,
[Parameter(Mandatory=$true)]
[validateSet("Equal","GreaterThan","GreaterThanOrEqual","LessThan" ,"LessThanOrEqual" ,"NotEqual")]
[string]$operator
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
if ($PSCmdlet.ParameterSetName -eq "byString") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$value)
}
if ($PSCmdlet.ParameterSetName -eq "byGuid") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterConditionForGuid($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$guidValue)
}
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$customFilter
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$tableQuery.FilterString = $customFilter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$entity
)
# Only one entity at a time can be updated
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Update operation can happen on only one entity at a time, not in a list/array of entities."
}
$updatedEntity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $entity.PartitionKey, $entity.RowKey
# Iterating over PS Object properties to add to the updated entity
foreach ($prop in $entity.psobject.Properties)
{
if (($prop.name -ne "PartitionKey") -and ($prop.name -ne "RowKey") -and ($prop.name -ne "Timestamp") -and ($prop.name -ne "Etag") -and ($prop.name -ne "TableTimestamp"))
{
$updatedEntity.Properties.Add($prop.name, $prop.Value)
}
}
$updatedEntity.ETag = $entity.Etag
# Updating the dynamic table entity to the table
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Replace(`$updatedEntity)")))
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="byEntityPSObjectObject")]
$entity,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$partitionKey,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$rowKey
)
begin
{
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Delete operation cannot happen on an array of entities, altough you can pipe multiple items."
}
$results = @()
}
process
{
if ($PSCmdlet.ParameterSetName -eq "byEntityPSObjectObject")
{
$partitionKey = $entity.PartitionKey
$rowKey = $entity.RowKey
}
$entityToDelete = invoke-expression "[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN](`$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Retrieve(`$partitionKey,`$rowKey))).Result"
if ($entityToDelete -ne $null)
{
$results += $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Delete(`$entityToDelete)"))
}
}
end
{
return ,$results
}
}
函数Get-AzureStorageTableRowByColumnName
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$partitionKey,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$rowKey,
[Parameter(Mandatory=$false)]
[hashtable]$property,
[Switch]$UpdateExisting
)
# Creates the table entity with mandatory partitionKey and rowKey arguments
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
# Adding the additional columns to the table entity
foreach ($prop in $property.Keys)
{
if ($prop -ne "TableTimestamp")
{
$entity.Properties.Add($prop, $property.Item($prop))
}
}
if($UpdateExisting)
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insertorreplace(`$entity)")))
}
else
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insert(`$entity)")))
}
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[string]$partitionKey
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition("PartitionKey",`
[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::Equal,$partitionKey)
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$columnName,
[Parameter(ParameterSetName="byString",Mandatory=$true)]
[AllowEmptyString()]
[string]$value,
[Parameter(ParameterSetName="byGuid",Mandatory=$true)]
[guid]$guidValue,
[Parameter(Mandatory=$true)]
[validateSet("Equal","GreaterThan","GreaterThanOrEqual","LessThan" ,"LessThanOrEqual" ,"NotEqual")]
[string]$operator
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
if ($PSCmdlet.ParameterSetName -eq "byString") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$value)
}
if ($PSCmdlet.ParameterSetName -eq "byGuid") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterConditionForGuid($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$guidValue)
}
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$customFilter
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$tableQuery.FilterString = $customFilter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$entity
)
# Only one entity at a time can be updated
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Update operation can happen on only one entity at a time, not in a list/array of entities."
}
$updatedEntity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $entity.PartitionKey, $entity.RowKey
# Iterating over PS Object properties to add to the updated entity
foreach ($prop in $entity.psobject.Properties)
{
if (($prop.name -ne "PartitionKey") -and ($prop.name -ne "RowKey") -and ($prop.name -ne "Timestamp") -and ($prop.name -ne "Etag") -and ($prop.name -ne "TableTimestamp"))
{
$updatedEntity.Properties.Add($prop.name, $prop.Value)
}
}
$updatedEntity.ETag = $entity.Etag
# Updating the dynamic table entity to the table
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Replace(`$updatedEntity)")))
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="byEntityPSObjectObject")]
$entity,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$partitionKey,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$rowKey
)
begin
{
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Delete operation cannot happen on an array of entities, altough you can pipe multiple items."
}
$results = @()
}
process
{
if ($PSCmdlet.ParameterSetName -eq "byEntityPSObjectObject")
{
$partitionKey = $entity.PartitionKey
$rowKey = $entity.RowKey
}
$entityToDelete = invoke-expression "[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN](`$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Retrieve(`$partitionKey,`$rowKey))).Result"
if ($entityToDelete -ne $null)
{
$results += $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Delete(`$entityToDelete)"))
}
}
end
{
return ,$results
}
}
函数Get-AzureStorageTableRowByCustomFilter
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$partitionKey,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$rowKey,
[Parameter(Mandatory=$false)]
[hashtable]$property,
[Switch]$UpdateExisting
)
# Creates the table entity with mandatory partitionKey and rowKey arguments
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
# Adding the additional columns to the table entity
foreach ($prop in $property.Keys)
{
if ($prop -ne "TableTimestamp")
{
$entity.Properties.Add($prop, $property.Item($prop))
}
}
if($UpdateExisting)
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insertorreplace(`$entity)")))
}
else
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insert(`$entity)")))
}
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[string]$partitionKey
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition("PartitionKey",`
[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::Equal,$partitionKey)
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$columnName,
[Parameter(ParameterSetName="byString",Mandatory=$true)]
[AllowEmptyString()]
[string]$value,
[Parameter(ParameterSetName="byGuid",Mandatory=$true)]
[guid]$guidValue,
[Parameter(Mandatory=$true)]
[validateSet("Equal","GreaterThan","GreaterThanOrEqual","LessThan" ,"LessThanOrEqual" ,"NotEqual")]
[string]$operator
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
if ($PSCmdlet.ParameterSetName -eq "byString") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$value)
}
if ($PSCmdlet.ParameterSetName -eq "byGuid") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterConditionForGuid($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$guidValue)
}
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$customFilter
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$tableQuery.FilterString = $customFilter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$entity
)
# Only one entity at a time can be updated
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Update operation can happen on only one entity at a time, not in a list/array of entities."
}
$updatedEntity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $entity.PartitionKey, $entity.RowKey
# Iterating over PS Object properties to add to the updated entity
foreach ($prop in $entity.psobject.Properties)
{
if (($prop.name -ne "PartitionKey") -and ($prop.name -ne "RowKey") -and ($prop.name -ne "Timestamp") -and ($prop.name -ne "Etag") -and ($prop.name -ne "TableTimestamp"))
{
$updatedEntity.Properties.Add($prop.name, $prop.Value)
}
}
$updatedEntity.ETag = $entity.Etag
# Updating the dynamic table entity to the table
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Replace(`$updatedEntity)")))
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="byEntityPSObjectObject")]
$entity,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$partitionKey,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$rowKey
)
begin
{
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Delete operation cannot happen on an array of entities, altough you can pipe multiple items."
}
$results = @()
}
process
{
if ($PSCmdlet.ParameterSetName -eq "byEntityPSObjectObject")
{
$partitionKey = $entity.PartitionKey
$rowKey = $entity.RowKey
}
$entityToDelete = invoke-expression "[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN](`$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Retrieve(`$partitionKey,`$rowKey))).Result"
if ($entityToDelete -ne $null)
{
$results += $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Delete(`$entityToDelete)"))
}
}
end
{
return ,$results
}
}
函数更新AzureStorageTableRow
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$partitionKey,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$rowKey,
[Parameter(Mandatory=$false)]
[hashtable]$property,
[Switch]$UpdateExisting
)
# Creates the table entity with mandatory partitionKey and rowKey arguments
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
# Adding the additional columns to the table entity
foreach ($prop in $property.Keys)
{
if ($prop -ne "TableTimestamp")
{
$entity.Properties.Add($prop, $property.Item($prop))
}
}
if($UpdateExisting)
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insertorreplace(`$entity)")))
}
else
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insert(`$entity)")))
}
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[string]$partitionKey
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition("PartitionKey",`
[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::Equal,$partitionKey)
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$columnName,
[Parameter(ParameterSetName="byString",Mandatory=$true)]
[AllowEmptyString()]
[string]$value,
[Parameter(ParameterSetName="byGuid",Mandatory=$true)]
[guid]$guidValue,
[Parameter(Mandatory=$true)]
[validateSet("Equal","GreaterThan","GreaterThanOrEqual","LessThan" ,"LessThanOrEqual" ,"NotEqual")]
[string]$operator
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
if ($PSCmdlet.ParameterSetName -eq "byString") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$value)
}
if ($PSCmdlet.ParameterSetName -eq "byGuid") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterConditionForGuid($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$guidValue)
}
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$customFilter
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$tableQuery.FilterString = $customFilter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$entity
)
# Only one entity at a time can be updated
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Update operation can happen on only one entity at a time, not in a list/array of entities."
}
$updatedEntity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $entity.PartitionKey, $entity.RowKey
# Iterating over PS Object properties to add to the updated entity
foreach ($prop in $entity.psobject.Properties)
{
if (($prop.name -ne "PartitionKey") -and ($prop.name -ne "RowKey") -and ($prop.name -ne "Timestamp") -and ($prop.name -ne "Etag") -and ($prop.name -ne "TableTimestamp"))
{
$updatedEntity.Properties.Add($prop.name, $prop.Value)
}
}
$updatedEntity.ETag = $entity.Etag
# Updating the dynamic table entity to the table
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Replace(`$updatedEntity)")))
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="byEntityPSObjectObject")]
$entity,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$partitionKey,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$rowKey
)
begin
{
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Delete operation cannot happen on an array of entities, altough you can pipe multiple items."
}
$results = @()
}
process
{
if ($PSCmdlet.ParameterSetName -eq "byEntityPSObjectObject")
{
$partitionKey = $entity.PartitionKey
$rowKey = $entity.RowKey
}
$entityToDelete = invoke-expression "[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN](`$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Retrieve(`$partitionKey,`$rowKey))).Result"
if ($entityToDelete -ne $null)
{
$results += $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Delete(`$entityToDelete)"))
}
}
end
{
return ,$results
}
}
函数Remove AzureStorageTableRow
{
[CmdletBinding()]
param
(
[参数(必需=$true)]
$table
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$partitionKey,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$rowKey,
[Parameter(Mandatory=$false)]
[hashtable]$property,
[Switch]$UpdateExisting
)
# Creates the table entity with mandatory partitionKey and rowKey arguments
$entity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $partitionKey, $rowKey
# Adding the additional columns to the table entity
foreach ($prop in $property.Keys)
{
if ($prop -ne "TableTimestamp")
{
$entity.Properties.Add($prop, $property.Item($prop))
}
}
if($UpdateExisting)
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insertorreplace(`$entity)")))
}
else
{
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::insert(`$entity)")))
}
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[string]$partitionKey
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition("PartitionKey",`
[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::Equal,$partitionKey)
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$columnName,
[Parameter(ParameterSetName="byString",Mandatory=$true)]
[AllowEmptyString()]
[string]$value,
[Parameter(ParameterSetName="byGuid",Mandatory=$true)]
[guid]$guidValue,
[Parameter(Mandatory=$true)]
[validateSet("Equal","GreaterThan","GreaterThanOrEqual","LessThan" ,"LessThanOrEqual" ,"NotEqual")]
[string]$operator
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
if ($PSCmdlet.ParameterSetName -eq "byString") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterCondition($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$value)
}
if ($PSCmdlet.ParameterSetName -eq "byGuid") {
[string]$filter = `
[Microsoft.WindowsAzure.Storage.Table.TableQuery]::GenerateFilterConditionForGuid($columnName,[Microsoft.WindowsAzure.Storage.Table.QueryComparisons]::$operator,$guidValue)
}
$tableQuery.FilterString = $filter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true)]
[string]$customFilter
)
# Filtering by Partition Key
$tableQuery = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.TableQuery,$assemblySN"
$tableQuery.FilterString = $customFilter
$result = $table.CloudTable.ExecuteQuery($tableQuery)
if (-not [string]::IsNullOrEmpty($result))
{
return (Get-PSObjectFromEntity -entityList $result)
}
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$entity
)
# Only one entity at a time can be updated
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Update operation can happen on only one entity at a time, not in a list/array of entities."
}
$updatedEntity = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN" -ArgumentList $entity.PartitionKey, $entity.RowKey
# Iterating over PS Object properties to add to the updated entity
foreach ($prop in $entity.psobject.Properties)
{
if (($prop.name -ne "PartitionKey") -and ($prop.name -ne "RowKey") -and ($prop.name -ne "Timestamp") -and ($prop.name -ne "Etag") -and ($prop.name -ne "TableTimestamp"))
{
$updatedEntity.Properties.Add($prop.name, $prop.Value)
}
}
$updatedEntity.ETag = $entity.Etag
# Updating the dynamic table entity to the table
return ($table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Replace(`$updatedEntity)")))
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="byEntityPSObjectObject")]
$entity,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$partitionKey,
[Parameter(Mandatory=$true,ParameterSetName="byPartitionandRowKeys")]
[AllowEmptyString()]
[string]$rowKey
)
begin
{
$updatedEntityList = @()
$updatedEntityList += $entity
if ($updatedEntityList.Count -gt 1)
{
throw "Delete operation cannot happen on an array of entities, altough you can pipe multiple items."
}
$results = @()
}
process
{
if ($PSCmdlet.ParameterSetName -eq "byEntityPSObjectObject")
{
$partitionKey = $entity.PartitionKey
$rowKey = $entity.RowKey
}
$entityToDelete = invoke-expression "[Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity,$assemblySN](`$table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Retrieve(`$partitionKey,`$rowKey))).Result"
if ($entityToDelete -ne $null)
{
$results += $table.CloudTable.Execute((invoke-expression "[Microsoft.WindowsAzure.Storage.Table.TableOperation,$assemblySN]::Delete(`$entityToDelete)"))
}
}
end
{
return ,$results
}
}
别名
新别名-名称添加AzureStorageTableRow-值添加StorageTableRow根据我的理解,您希望使用PowerShell来管理Azure表存储。如果是这样,您可以使用模块来实现它 比如说
Install-Module -Name AzTable
$groupName=""
$StorageAccountName = ""
$StorageAccountKey = ""
$vaule=" "
$context = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$tables = Get-AzStorageTable -Context $context
Foreach($table in $tables){
$table = Get-AzTableTable -storageAccountName $StorageAccountName -resourceGroup $groupName="" -TableName
$entities=Get-AzTableRow -Table $table
ForEach($e in $entities){
$entity = New-Object Microsoft.Azure.Cosmos.Table.DynamicTableEntity($e.PartitionKey,$e.RowKey)
$entity.Properties.Add("Name", $vaue)
$table.Execute([Microsoft.Azure.Cosmos.Table.TableOperation]::InsertOrMerge($entity))
Get-AzTableRow -Table $table -PartitionKey $e.PartitionKey -RowKey $e.RowKey
}
}
有关详细信息,请参阅
您能告诉我您想做什么吗?据我了解,您想使用PowerShell来管理Azure表存储。如果是这样,您可以参考。此外,您能否详细描述您的问题l并告诉我您想做什么?