0
votes

I have a multiple Azure Storage Accounts. I want to create the folder structure inside the Azure Storage blob containers and insert some data into it using PowerShell.

So, can anyone suggest me how to write the PowerShell script for creating sub directories inside the blob containers and insert some data into it.

1
Hi, please refer to stackoverflow.com/help/how-to-ask (in particular how you've attempted to solve the problem yourself). I didn't vote down, but I suspect it will be the feedback of those who did.Alex KeySmith

1 Answers

4
votes

In Azure storage blob containers does not really support creating folders, folders are created as part of the path when uploading the file to the container, so there is no separate action that only creates empty folder. For example:

folder1/image.png
folderA/folderB/image2.png

And the SDK has API that supports getting the files based on "folder" path.

Powershell example of "creating" folder1 is:

Connect-AzureRmAccount

$storageAccount = Get-AzureRmStorageAccount -ResourceGroupName 'myresourcegroup' `
-Name 'storageaccount' 

Set-AzureStorageBlobContent -File C:\tmp\0001.png `
-Container files `
-Blob 'folder1/0001.png' `
-Context $storageAccount.Context

This will respectively "create" folder1 and upload 0001.png to that folder