George
George

Reputation: 197

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

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.

Powershell script to copy files from server to azure blob container

Upvotes: 0

Views: 1079

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136346

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 
}

Upvotes: 1

Related Questions