gpt4 book ai didi

使用 PowerShell 的 Azure blob 版本保留详细信息

转载 作者:行者123 更新时间:2023-12-03 06:08:18 26 4
gpt4 key购买 nike

我正在尝试查找容器中的所有 blob 版本及其保留期。基本上我们想要获取这些数据以查看可以从 blob 版本中删除哪些内容。我可以在 Azure 门户中看到版本的保留期,但在 PowerShell 中看不到。我正在尝试下面的脚本。有人可以指导我如何使用 PowerShell 获取相同的详细信息吗?

Connect-AzAccount

Set-AzContext -Subscription "xxxxxxxxxxxxxxx"

$resourceGroup = "rg-dev-001"
$storageAccountName = "stdev"
$containerName = "offload"

$stoaccount = Get-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroup

$versions = Get-AzStorageBlob -Container $containerName -Context $stoaccount.Context -IncludeVersion -IncludeDeleted | where { $_.IsLatestVersion -NE 'True' }

最佳答案

I can see the retention period of versions in the Azure portal but not in PowerShell.

在我的环境中,我有一个具有保留期的文件和另一个没有保留期的文件。

门户:

enter image description here

您可以使用以下 PowerShell 脚本来检索信息。

命令:

Connect-AzAccount

Set-AzContext -Subscription "xxxxxxxxxxxxxxx"

$resourceGroup = "rg-dev-001"
$storageAccountName = "stdev"
$containerName = "offload"

$stoaccount = Get-AzStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroup

$versions = Get-AzStorageBlob -Container $containerName -Context $stoaccount.Context -IncludeVersion -IncludeDeleted

Foreach($version in $versions){
$properties = $version.BlobClient.GetProperties()
Write-Host "URL: $($version.Context.BlobEndPoint)$($version.Container.Name)/$($version.Name)"
Write-Host "TYPE: $($properties.Value.BlobType)"
Write-Host "SIZE: $($properties.Value.ContentLength / 1KB) KiB"
Write-Host "VERSION ID: $($properties.Value.VersionId)"
Write-Host "RETENTION PERIOD: $($properties.Value.ImmutabilityPolicy.ExpiresOn)"
write-Host " "
}

输出:

URL: https://venkat789.blob.core.windows.net//example.pdf
TYPE: Block
SIZE: 22.166015625 KiB
VERSION ID: 2023-09-11T15:05:29.3224280Z
RETENTION PERIOD: 12/20/2023 15:06:41 +00:00

URL: https://venkat789.blob.core.windows.net//table403 (1).txt
TYPE: Block
SIZE: 0.376953125 KiB
VERSION ID: 2023-09-11T15:19:15.9233123Z
RETENTION PERIOD:

enter image description here

引用:

Manage block blobs with PowerShell - Azure Storage | Microsoft Learn

关于使用 PowerShell 的 Azure blob 版本保留详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77081859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com