Hello Rohit
I understand that you require the upload of thousands of blobs, each associated with distinct index tag values for legacylastcreated and legacylastmodified.
Please be informed that AZ Copy is capable of adding index tags while uploading blobs, making it a highly effective method for managing this process. You can utilize the --blob-tags parameter to define the index tags along with their corresponding values.
The --blob-tags parameter allows for a list of key-value pairs separated by semicolons, formatted as key=value. In your case, it would appear as follows: **--blob-tags="legacylastcreated=2025-10-26T10:00:00Z;legacylastmodified=2025-10-26T12:00:00Z"**You can use either PowerShell or Bash in conjunction with Azure CLI to manage the process. The script will loop through each file you want to upload and within the loop, the script will retrieve the values of legacylastcreated and legacylastmodified, which are derived from the timestamps of the file. The script will then use AZ Copy to upload the file, including the unique tag values.
Please be informed that Your SAS token needs to possess permissions for both writing blobs and setting tags. Utilize --permissions rw,t (or add t for tags). The yyyy-MM-ddTHH:mm:ssZ
format is crucial for consistent tag values. If it's for your production use, add error checking to your script because the AZ Copy is already optimized; however, the script introduces some additional overhead. For very large uploads, it is advisable to implement optimization strategies within your scripting.
Bash script:
#!/bin/bash
# Set your variables sourcePath="/path/to/your/source/folder"
# Replace storageAccountName="<your-storage-account-name>"
# Replace containerName="<your-container-name>"
# Replace sasToken="<YourSASToken>"
# Replace with a SAS token with 'write' and 'tag' permissions # Construct the destination URL destinationUrl="https://$storageAccountName.blob.core.windows.net/$containerName"
# Loop through the files for file in "$sourcePath"/*; do if [ -f "$file"; then
# Get the file's creation and last modification times in UTC lastCreated=$(date -u -r "$file" +"%Y-%m-%dT%H:%M:%SZ") lastModified=$(date -u -r "$file" +"%Y-%m-%dT%H:%M:%SZ") # Construct the tag string tags="legacylastcreated=$lastCreated&legacylastmodified=$lastModified"
# Upload the file with tags using AzCopy azcopy copy \ "$file" \ "$destinationUrl/$(basename "$file")" \ --blob-tags="$tags" \ --log-level=INFO
# Optional: For logging echo "Uploaded $(basename "$file") with tags: $tags"
# Optional: Print progress fi done echo "Upload complete."
PowerShell script:
Set your variables $sourcePath = "C:\Your\Source\Folder"
# Replace with your folder $storageAccountName = "<your-storage-account-name>"
# Replace $containerName = "<your-container-name>" # Replace $sasToken = "<YourSASToken>" # Replace with a SAS token with 'write' and 'tag' permissions
# Construct the destination URL $destinationUrl = "https://$storageAccountName.blob.core.windows.net/$containerName"
# Get the files $files = Get-ChildItem -Path $sourcePath -File
# Loop through the files foreach ($file in $files) { # Get the file's creation and last write times in UTC format $lastCreated = $file.CreationTimeUtc.ToString("yyyy-MM-ddTHH:mm:ssZ") $lastModified = $file.LastWriteTimeUtc.ToString("yyyy-MM-ddTHH:mm:ssZ") # Construct the tag string $tags = "legacylastcreated=$lastCreated&legacylastmodified=$lastModified"
# Upload the file with tags using AzCopy azcopy copy "$($file.FullName)" "$destinationUrl/$($file.Name)" --blob-tags="$tags" --log-level=INFO
# Optional: For logging Write-Host "Uploaded $($file.Name) with tags: $($tags)"
# Optional: Print progress } Write-Host "Upload complete."
Note- If you don't need to use the tags for searching or filtering blobs, consider using metadata instead. https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-blobs-properties-metadata
Hope the above answer helps! Please let us know do you have any further queries.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.