我想根据某些条件从azure存储表中删除记录。我在天蓝色存储表中有像datemodified这样的列。 我的查询看起来像
datemodifed < (Get-Date).ToUniversalTime().AddDays(-10)
任何人都可以告诉我如何使用powershell脚本根据上述条件逐个删除记录。提前致谢
答案 0 :(得分:0)
Working with Azure Storage Tables from PowerShell
TableOperation.Delete接受表实体。见这里:https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.table.tableoperation.delete.aspx
在这里查看TableQuery类https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.table.tablequery_methods.aspx
参考:https://www.wintellect.com/deleting-entities-in-windows-azure-table-storage/
答案 1 :(得分:0)
使用这个命令:
$entityToDelete | Remove-AzTableRow -table $cloudTable
要获取 $cloudTable,您需要先获取存储帐户和实体的上下文。 例如你可以使用这个脚本:
$storageAccountName = "MyStorage"
$resourceGroup = "MyRG"
$tableName = "MyTable"
$columnName = "MyColum"
$value = "EntityValueToSearch"
$storageAccount = Get-AzStorageAccount `
-ResourceGroupName $resourceGroup `
-Name $storageAccountName
$ctx = $storageAccount.Context
$storageTable = Get-AzStorageTable –Name $tableName –Context $ctx
$cloudTable = ($storageTable).CloudTable
[string]$filter = `
[Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition($columnName,`
[Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,$value)
# Get entity
$entityToDelete = Get-AzTableRow `
-table $cloudTable `
-customFilter $filter
$entityToDelete | Remove-AzTableRow -table $cloudTable
欲了解更多信息和一个很好的参考: https://docs.microsoft.com/en-us/azure/storage/tables/table-storage-how-to-use-powershell#deleting-table-entities