-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set-AzStorageBlobTag does not allow clearing tags from blob #21551
Comments
Thank you for your feedback. This has been routed to the support team for assistance. |
@johnwc Thanks for your feedback! We will investigate and update as appropriate. |
Thanks for the reporting this issue! I have found the root cause, and will raise a PR to fix it soon. Besides that, before the issue is fixed, you can clean the tags on a blob with following PSH script: $blob = Get-AzStorageBlob -Container '$web' -Blob 'my/blob.jpg' -Context $ctx
$Tags = New-Object System.Collections.Generic.Dictionary"[String,String]"
$blob.BlobBaseClient.SetTags($Tags) |
@blueww should there be a Delete-AzStorageBlobTags for this, instead of allowing a empty array? |
"Blob Tags" is a whole object, we can only set/get it as a whole from server. |
@blueww we have 100k+ blobs, was hoping not to have to pull the entire object for each. |
Do you mean you don't want to Run Get-AzStorageBlob on each blob? List following script will first list all blobs in single container, then clear tags on each blob.
|
@blueww I'm not seeing the cmdlet using the correct endpoint when trying to list blobs by tag. I actually don't see it using the TagCondition at all. It's calling $stg | Get-AzStorageBlob -Container '$web' -MaxCount 12 -TagCondition """TagName"" = 'abc'"
DEBUG: 11:00:59 AM - Init Operation Context for 'GetAzureStorageBlobCommand' with client request id Azure-Storage-PowerShell-8e00dc58-17b5-4cd0-a416-0ad8d50dcb1c. If you want to get more details, please add "-Debug" to your command.
DEBUG: 11:00:59 AM - GetAzureStorageBlobCommand begin processing with ParameterSet 'BlobName'.
DEBUG: 11:00:59 AM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 11:00:59 AM - Use storage account 'xxxxx' from storage context.
DEBUG: 11:00:59 AM - Start 35th remote call, method: , destination: https://xxxxxx.blob.core.windows.net/$web?restype=container.
DEBUG: Request [bf09fe15-ee23-4935-9b61-19799c5d9dc6] GET https://xxxxxx.blob.core.windows.net/$web?restype=container&comp=list&prefix=&maxresults=12&include=Copy%2CMetadata%2CSnapshots
x-ms-version:2021-10-04
Accept:application/xml
User-Agent:AzurePowershell/v1.0.0,azsdk-net-Storage.Blobs/12.14.0,(.NET 7.0.3; Microsoft Windows 10.0.22621)
x-ms-client-request-id:bf09fe15-ee23-4935-9b61-19799c5d9dc6
x-ms-return-client-request-id:true
x-ms-date:Mon, 17 Apr 2023 16:00:59 GMT
Authorization:REDACTED
client assembly: Azure.Storage.Blobs
DEBUG: Response [bf09fe15-ee23-4935-9b61-19799c5d9dc6] 200 OK (00.1s)
Transfer-Encoding:chunked
Server:Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id:17c7e91a-701e-0019-3f45-714f5c000000
x-ms-client-request-id:bf09fe15-ee23-4935-9b61-19799c5d9dc6
x-ms-version:2021-10-04
Date:Mon, 17 Apr 2023 16:01:00 GMT
Content-Type:application/xml
Accept:application/xml
User-Agent:AzurePowershell/v1.0.0,azsdk-net-Storage.Blobs/12.14.0,(.NET 7.0.3; Microsoft Windows 10.0.22621)
x-ms-client-request-id:48d215e2-e8e6-417f-a64f-468b679dcd4b
x-ms-return-client-request-id:true
x-ms-date:Mon, 17 Apr 2023 15:58:34 GMT
Authorization:REDACTED
client assembly: Azure.Storage.Blobs
DEBUG: Response [48d215e2-e8e6-417f-a64f-468b679dcd4b] 200 OK (00.2s)
Transfer-Encoding:chunked
Server:Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id:4f610f1e-401e-004f-5145-71beb3000000
x-ms-client-request-id:48d215e2-e8e6-417f-a64f-468b679dcd4b
x-ms-version:2021-10-04
Date:Mon, 17 Apr 2023 15:58:34 GMT
Content-Type:application/xml |
I see you would like to find blob by tag filter, this is a different API from list blob from container, then you should use the following cmdlet :
Please note, |
What's the purpose of TagCondition? Setting it doesn't seem to do anything. |
For "-TagCondition" it mostly works on the single blob operation, only the blob matched the tag condition will execute the operation. See : https://learn.microsoft.com/en-us/rest/api/storageservices/specifying-conditional-headers-for-blob-service-operations#tags-conditional-operations However, to filter multiple blobs from container / account, you should use -TagFilterSqlExpression, which is the search expression, see details in https://learn.microsoft.com/en-us/rest/api/storageservices/find-blobs-by-tags?tabs=azure-ad#constructing-a-search-expression. BTW, Clear blob Tag with following command is already supported on Az.Storage 5.6.0. Set-AzStorageBlobTag -Container $containerName -Blob test.txt -Context $ctx -Tag @{} So I will close this issue. Feel free to contact us again if you need any further assistance on Azure PowerShell. |
@blueww We have a couple 100k blobs that we need to set tags to, how can we update them in bulk rather than calling Set-AzStorageBlobTag per blob? |
Powershell depends on .net SDK, and .net SDK depends on rest API. My suggestion is you can list blob chunk by chunk (see sample), and set blob tag on each list out blob. If you would like rest API (and server) support set blob tag in bulk in the future, you can raise you request in MS portal like following picture. |
Description
The documentation for blob tags states to remove all tags, pass a empty hash array to the API. Doing so in PowerShell causes an error.
Set-AzStorageBlobTag: Cannot validate argument on parameter 'Tag'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again.
Issue script & Debug output
Environment data
Module versions
Error output
The text was updated successfully, but these errors were encountered: