Upload files to subfloders in container using Powershell script.

Ashish Sinha 41 Reputation points
2020-11-01T16:07:49.027+00:00

Hi Guys,

I am trying to upload blob to container which has sub folders in it using powershell.
Here is my code:-

Connect-AzureRmAccount

$Keys = Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $storagename

$keys.Item(0).Value

$StorageContext = New-AzureStorageContext -StorageAccountName  - $storagename StorageAccountKey $Keys.Item(0).value;

$UploadFile = @{

    Context = $StorageContext;

    Container = 'landing-area';

    File = $file;

    }

Set-AzureStorageBlobContent @UploadFile -Force;

So my container name is 'landing-area' and it has multiple sub-folders inside of it.

I want to upload my blobs in one of those folder but i cant seem to get it right

when i replace Container with 'landing-area/test' it throws me error as:

Set-AzureStorageBlobContent : Container name 'landing-area/Test' is invalid.
Valid names start and end with a lower case letter or a number and has in
between a lower case letter, number or dash with no consecutive dashes and is
3 through 63 characters long.

Can anyone please help how can i achieve this?

Thanks,
Ashish

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,778 questions
{count} votes

Accepted answer
  1. deherman-MSFT 36,661 Reputation points Microsoft Employee
    2020-11-02T19:50:10.573+00:00

    @Ashish Sinha

    Directories in blob storage are considered virtual and should be included as part of the blob name. There is a similar question on StackOverflow which you might find helpful. Basically you will want to use the -Blob option for Set-AzureStorageBlobContent and include the folder(s) as part of the name, such as "test/myfile.txt".

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


2 additional answers

Sort by: Most helpful
  1. Ashish Sinha 41 Reputation points
    2020-11-02T14:11:34.77+00:00

    Hi Guys,

    So I found a different way to do it.

    My actual requirement was to refresh the Odata in excel file and saving the sheets in excel as CSV files and upload it to container which would be picked by ADF to copy in database.

    I created a powershell script that

    1. Run the macros to refresh the sheets
    2. Save these sheets as csv on One Drive

    Then i created a UiFlow using Power Automate desktop to run the power shell script. This UiFlow is called in Team Flows in Power Automate cloud which loops through the One Drive folder and put the files in Container.

    Then in ADF my Event trigger would run the pipeline.

    I think this is a long solution but I would really like to know how can i do this in One PowerShell script

    0 comments No comments

  2. Lachie Bunter 1 Reputation point
    2021-06-22T03:38:03.51+00:00

    just fyi last command

    should be Set-AzStorageBlobContent

    not Set-AzureStorageBlobContent

    at least as of my testing today.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.