【问题标题】:Merging two azure blobs to single blob using powershell使用 powershell 将两个 azure blob 合并为单个 blob
【发布时间】:2021-11-27 05:40:05
【问题描述】:
在 azure 容器中,有多个具有相同名称但扩展名不同的 blob(例如:file_01.txt、file_02.txt、file_03.txt)。
谁能告诉如何将这 3 个文件内容连接到单个文件内容(例如:- All_files.txt)并使用 azure powershell 脚本将其放在同一个容器中。
【问题讨论】:
标签:
azure
powershell
azure-blob-storage
azure-storage
【解决方案1】:
根据您的要求,我们创建了一个 PowerShell 脚本,用于将 blob 从您的存储帐户下载到本地,并将合并 blob 并上传回不同的容器。
这是 PowerShell 脚本:
$storagecontext = New-AzStorageContext -StorageAccountName '<storageaccoutName>' -StorageAccountKey '<storageAccountKey>'
$storagelist= Get-AzStorageBlob -Container '<containerName>' -Context $storagecontext
$storagearray =$storagelist
foreach($storagelist in $storagearray)
{
Get-AzStorageBlobContent -Container testblob -Blob $storagelist.Name -Context $storagecontext -Destination C:\Users\Downloads\
$name = $storagelist.Name
Get-Content C:\Users\Downloads\$($name) | Add-Content C:\Users\Downloads\Allfile.txt
}
az storage blob upload --container-name '<newUplodingContainerName>' -f 'C:\Users\Downloads\Allfile.txt' -n 'allfile.txt' --account-name '<storageAccountName>' --account-key '<storageAccountKey>'
这是上述 PowerShell 脚本的参考输出: