4

I have an Azure storage account with Blob containers and folders (also named containers?) within these blob containers. I have an Account Name and Account Key to access it and I can upload files using Microsoft Azure Storage Explorer. I have been searching for a simple script to upload files to a specific blob container but I have been able to find one. Uninstallig the RM-modules and installing the AZ-modules was already a challenge. The examples all seem to be very complicated (security is not an issue for this project) and I just cannot get them to work and I am newby to the subject.

Can anyone share a simple line of powershell script with me to do this?

2
  • Could you help us here with some more information that Are you looking for a PowerShell script to copy the blobs from local to Azure storage account? or to copy the files from one blob container to another blob container inside the storage account? Commented Jun 27, 2022 at 6:14
  • Thanks, it is meant to upload local files (vendor invoices in xml format) to an Axureblob storage. We receive xml-invoices from vendors. I convert/enrich them using powershell (xslt/regex) and then want to have them uploaded to Azure Blobstorage. All automatically when one of my colleagues places them in some local directory. I think the script that SrideviMachavarapu-MT provided will work fine if I can have it work without having to confirm my Microsoft login every time the script is run. Commented Jun 30, 2022 at 8:10

1 Answer 1

4

I tried to upload files to a specific blob container by using below PowerShell script and got the result successfully:

Connect-AzAccount

$ctx = New-AzStorageContext 
-StorageAccountName 'YourStorageAccountName' 
-StorageAccountKey 'YourStorageAccountKey' -Protocol Https

Set-AzStorageBlobContent 
-File "C:\Users\Downloads\YourFileName" `  //Your file path
-Container YourContainerName 
-Blob "YourFileName" `  
-Context $ctx

The file got uploaded to the blob container successfully like below:

enter image description here

To confirm the above, check in the Portal whether the file is uploaded or not like below:

enter image description here

Please note that, to run the above script you need Azure modules like Az.Accounts and Az.Storage modules. You can refer this MsDoc to install the same.

Reference:

Quickstart: Upload, download, and list blobs - Azure PowerShell - Azure Storage | Microsoft Docs

Sign up to request clarification or add additional context in comments.

4 Comments

Appologies for my late response but I was in a three day course. The script works quite nicely. An addition is that 1. It requests me to add -TenantID 'mytenantid' when I connect via Connect-AzAccount. 2. I continuously need to confirm my Microsoft login. It then gives me this browser screen and it continues: "Authentication complete. You can return to the application. Feel free to close this browser tab." I need to find out how I can add my username/password to the Connect-AzAccount-part.
You can refer this SO Thread to add your username/password to Connect-AzAccount automatically without prompts.
Thanks for the link. In particular the comment about not using MFA (Multi-Factor Authentication) did the trick for me. It seems to be working great with the few tests I have done. Thanks. This will be very helpfull for us!
Thanks for the update. Glad to know it helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.