英文:
Use powershell script to copy files from Azure VM to designated folder in the container of Azure Blob Storage
问题
我阅读了以下链接,了解如何将文件从虚拟机复制到 Azure Blob 存储帐户。然而,如果我需要将文件复制到容器中的指定文件夹,比如 containerName/UserA/Report/A 和 containerName/UserA/Report/B,根据虚拟机中的文件名来决定,命令会是什么样的呢?感谢您的帮助。
链接:https://stackoverflow.com/questions/55643403/powershell-script-to-copy-files-from-server-to-azure-blob-container
英文:
I read the following link for copying files from VM to the azure blob storage account. However, if i need to copy it to designated folder in the container, say, containerName/UserA/Report/A and containerName/UserA/Report/B according to the file name in VM.What will be the command look like? Thanks for your help.
答案1
得分: 1
你可以在文件名前添加所需的路径以设置 Blob 的名称。类似这样:
$context = New-AzStorageContext -StorageAccountName "<StorageAccountName>" -StorageAccountKey "<StorageAccountKey>"
$files = (Get-ChildItem "C:\Users\xxxx\Desktop\test" -recurse).FullName
foreach($file in $files){
$blobName = "UserA/Report/$file"
Set-AzStorageBlobContent -Context $context -File "$file" -Container "<容器名称>" -Blob $blobName
}
请注意,你需要替换 "
英文:
You can prepend the desired path to the file name to set the name of the blob. Something like:
$context = New-AzStorageContext -StorageAccountName "<StorageAccountName>" -StorageAccountKey "<StorageAccountKey>"
$files = (Get-ChildItem "C:\Users\xxxx\Desktop\test" -recurse).FullName
foreach($file in $files){
$blobName = "UserA/Report/$file"
Set-AzStorageBlobContent -Context $context -File "$file" -Container "<container name>" -Blob $blobName
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论