{"id":3626,"date":"2026-01-14T15:51:59","date_gmt":"2026-01-14T21:51:59","guid":{"rendered":"https:\/\/microsoftgeek.com\/?p=3626"},"modified":"2026-01-14T15:51:59","modified_gmt":"2026-01-14T21:51:59","slug":"upload-and-download-files-from-azure-blob-storage-using-connection-string","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=3626","title":{"rendered":"Upload and Download files from Azure Blob Storage using Connection String"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">&#x1f4a1; Uploading \/ Downloading files Azure Blog Storage<\/h3>\n\n\n\n<p>The first thing we need to do is to install&nbsp;<strong>Az.Storage<\/strong>&nbsp;module, which in turn will also download&nbsp;<strong>Az.Accounts<\/strong>&nbsp;module.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Install-Module -Name 'Az.Storage' -Force -Verbose -Scope CurrentUser<\/pre>\n\n\n\n<p>I always like to use Force and Verbose parameters. Force makes sure it redownloads everything that is required and makes sure it&#8217;s up to date. Verbose adds a bit more information about what is happening. Install-Module tends to go slow, and things can look like nothing is happening. Once we have our modules installed, we need to define&nbsp;<strong>ConnectionString<\/strong>&nbsp;and&nbsp;<strong>ContainerName<\/strong>&nbsp;and use&nbsp;<strong>New-AzStorageContext<\/strong>. We then pass the Context variable to&nbsp;<strong>Get-AzStorageBlob<\/strong>&nbsp;to get a list of available files on the storage.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/evotec.xyz\/wp-content\/uploads\/2023\/01\/img_63c8357c4208e.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><br># define data<br>$DestinationFolder = \"$PSScriptRoot\\Downloads\"<br>$ContainerName = \"eclcontainer\"<br>$ConnectionString = \"DefaultEndpointsProtocol=https;AccountName=test;AccountKey=rrandomKeymXwY8\/+dPIHH8=;EndpointSuffix=core.windows.net\"<br><br># connect to blob storage<br>$Context = New-AzStorageContext -ConnectionString $ConnectionString<br><br># list current content<br>$ContainerStorage = Get-AzStorageBlob -Container $ContainerName -Context $Context<br>$ContainerStorage | Format-Table<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>It&#8217;s important to know that the blob storage is&nbsp;<strong>case-sensitive<\/strong>. That means you can upload multiple files with the same name but different casing. Downloading all available files is available by using&nbsp;<strong>foreach<\/strong>&nbsp;and&nbsp;<strong>Get-AzStorageBlobContent<\/strong>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># go thru each file and download<br>foreach ($File in $ContainerStorage) {<br>    $Destination = \"$DestinationFolder\\$($File.Name)\"<br>    Get-AzStorageBlobContent -Container $ContainerName -Blob $File.Name -Context $Context -Destination $Destination -Force<br>}<br><\/pre>\n\n\n\n<p>If you want to overwrite existing content, you need to use the&nbsp;<strong>Force<\/strong>&nbsp;switch. Otherwise, you will be prompted for every file on the disk. To upload the file, you have to use&nbsp;<strong>Set-AzStorageBlobContent<\/strong>. You can upload a file with the same name as it has on the drive by not providing the Blob parameter or providing it and giving it a different name on the storage.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># upload file to blob storage\n$SourceFile = \"$PSScriptRoot\\Downloads\\test.PDF\"\n# upload file to blob storage but without changing the name\nSet-AzStorageBlobContent -File $SourceFile -Container $ContainerName -Context $Context\n# upload file to blob storage and change the name\n$DestinationFile = \"test1.pdf\"\nSet-AzStorageBlobContent -File $SourceFile -Container $ContainerName -Context $Context -Blob $DestinationFile<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>And that&#8217;s it. You now know how to upload and download files from&nbsp;<strong>Azure Blob Storage<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f4a1; Uploading \/ Downloading files Azure Blog Storage The first thing we need to do is to install&nbsp;Az.Storage&nbsp;module, which in turn will also download&nbsp;Az.Accounts&nbsp;module. Install-Module -Name &#8216;Az.Storage&#8217; -Force -Verbose -Scope CurrentUser I always like to use Force and Verbose parameters. Force makes sure it redownloads everything that is required and makes sure it&#8217;s up to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,35],"tags":[],"class_list":["post-3626","post","type-post","status-publish","format-standard","hentry","category-azure","category-cloud-computing"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3626"}],"version-history":[{"count":1,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3626\/revisions"}],"predecessor-version":[{"id":3627,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3626\/revisions\/3627"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}