Use powershell script to copy files from Azure VM to designated folder in the container of Azure Blob Storage

huangapple go评论61阅读模式
英文:

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.

https://stackoverflow.com/questions/55643403/powershell-script-to-copy-files-from-server-to-azure-blob-container

答案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 &quot;&lt;StorageAccountName&gt;&quot; -StorageAccountKey &quot;&lt;StorageAccountKey&gt;&quot;
$files = (Get-ChildItem &quot;C:\Users\xxxx\Desktop\test&quot; -recurse).FullName
foreach($file in $files){
    $blobName = &quot;UserA/Report/$file&quot;
    Set-AzStorageBlobContent -Context $context -File &quot;$file&quot; -Container &quot;&lt;container name&gt;&quot; -Blob $blobName 
}

huangapple
  • 本文由 发表于 2023年5月24日 18:55:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定