question

AshishSinha-1249 avatar image
0 Votes"
AshishSinha-1249 asked LachieBunter-6045 answered

Upload files to subfloders in container using Powershell script.

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried a way to upload the entire folder 'Test' which has files but in container I have and archive folder where i move the file after ELT from ADF. So if i overwrite the Test folder in container my archive folder would be deleted.

0 Votes 0 ·
deherman-MSFT avatar image
0 Votes"
deherman-MSFT answered AshishSinha-1249 commented

@AshishSinha-1249

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @deherman-MSFT . Appreciate it. I was able to load the folders and files inside my container. I had to change a part of the code according to the folder I had in the substring part and it worked.

0 Votes 0 ·
LachieBunter-6045 avatar image
0 Votes"
LachieBunter-6045 answered

just fyi last command

should be Set-AzStorageBlobContent

not Set-AzureStorageBlobContent

at least as of my testing today.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AshishSinha-1249 avatar image
0 Votes"
AshishSinha-1249 answered

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




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.