Skip to content

Commit 1ebe15c

Browse files
committed
add examples to list versions in portal, PS, CLI
1 parent 1256e21 commit 1ebe15c

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed
43.7 KB
Loading

articles/storage/blobs/versioning-enable.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: normesta
77

88
ms.service: storage
99
ms.topic: how-to
10-
ms.date: 06/07/2021
10+
ms.date: 01/25/2023
1111
ms.author: normesta
1212
ms.subservice: blobs
1313
ms.custom: devx-track-azurepowershell
@@ -21,6 +21,8 @@ This article shows how to enable or disable blob versioning for the storage acco
2121

2222
## Enable blob versioning
2323

24+
You can enable blob versioning with the Azure portal, PowerShell, Azure CLI, or an Azure Resource Manager template.
25+
2426
# [Azure portal](#tab/portal)
2527

2628
To enable blob versioning for a storage account in the Azure portal:
@@ -29,7 +31,7 @@ To enable blob versioning for a storage account in the Azure portal:
2931
1. Under **Blob service**, choose **Data protection**.
3032
1. In the **Versioning** section, select **Enabled**.
3133

32-
:::image type="content" source="media/versioning-enable/portal-enable-versioning.png" alt-text="Screenshot showing how to enable blob versioning in Azure portal":::
34+
:::image type="content" source="media/versioning-enable/portal-enable-versioning.png" alt-text="Screenshot showing how to enable blob versioning in Azure portal":::
3335

3436
# [PowerShell](#tab/powershell)
3537

@@ -91,6 +93,63 @@ For more information about deploying resources with templates in the Azure porta
9193

9294
---
9395

96+
## List blob versions with .NET
97+
98+
To display a blob's versions, use the Azure portal, PowerShell, or Azure CLI. You can also list a blob's versions using one of the Blob Storage SDKs.
99+
100+
# [Azure portal](#tab/portal)
101+
102+
To list a blob's versions in the Azure portal:
103+
104+
1. Navigate to your storage account in the portal, then navigate to the container that contains your blob.
105+
1. Select the blob for which you want to list versions.
106+
1. Select the **Versions** tab to display the blob's versions.
107+
108+
:::image type="content" source="media/versioning-enable/portal-list-blob-versions.png" alt-text="Screenshot showing how to list blob versions in the Azure portal":::
109+
110+
# [PowerShell](#tab/powershell)
111+
112+
To list a blob's versions with PowerShell, call the [Get-AzStorageBlob](/powershell/module/az.storage/get-azstorageblob) command with the `-IncludeVersion` parameter:
113+
114+
```azurepowershell
115+
$account = Get-AzStorageAccount -ResourceGroupName <resource-group> -Name <storage-account>
116+
$ctx = $account.Context
117+
$container = "<container-name>"
118+
119+
$blobs = Get-AzStorageBlob -Container $container -Prefix "ab" -IncludeVersion -Context $ctx
120+
121+
foreach($blob in $blobs)
122+
{
123+
Write-Host $blob.Name
124+
Write-Host $blob.VersionId
125+
Write-Host $blob.IsLatestVersion
126+
}
127+
```
128+
129+
# [Azure CLI](#tab/azure-cli)
130+
131+
To list a blob's versions with Azure CLI, call the [az storage blob directory list](/cli/azure/storage/blob/directory#az-storage-blob-directory-list) command with the `--include v` parameter:
132+
133+
```azurecli
134+
storageAccount="<storage-account>"
135+
containerName="<container-name>"
136+
137+
az storage blob list \
138+
--container-name $containerName \
139+
--prefix "ab" \
140+
--query "[[].name, [].versionId]" \
141+
--account-name $storageAccount \
142+
--include v \
143+
--auth-mode login \
144+
--output tsv
145+
```
146+
147+
# [Template](#tab/template)
148+
149+
N/A
150+
151+
---
152+
94153
## Modify a blob to trigger a new version
95154

96155
The following code example shows how to trigger the creation of a new version with the Azure Storage client library for .NET, version [12.5.1](https://www.nuget.org/packages/Azure.Storage.Blobs/12.5.1) or later. Before running this example, make sure you have enabled versioning for your storage account.
@@ -99,7 +158,7 @@ The example creates a block blob, and then updates the blob's metadata. Updating
99158

100159
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/dotnet-v12/CRUD.cs" id="Snippet_UpdateVersionedBlobMetadata":::
101160

102-
## List blob versions
161+
## List blob versions with .NET
103162

104163
To list blob versions or snapshots with the .NET v12 client library, specify the [BlobStates](/dotnet/api/azure.storage.blobs.models.blobstates) parameter with the **Version** field.
105164

0 commit comments

Comments
 (0)