Download/Upload to Azure Storage Accounts with SAS-link and PowerShell

Super short blogpost today, just two commands on how you use SAS link to download and upload files with PowerShell/RestAPI. Same can be done with Python using a link like this. Yes, I know my SAS ID is in the code, but its not valid anymore šŸ™‚

# This is how you can upload and download a file to/from Azure Blob Storage using PowerShell and a SAS URL.
# For download the SAS URL must have read permissions and for upload it must have write permissions.
# Specify the filename to upload
$Filename = "picture.png"
# Replace with your actual SAS URL
$SasUrl = "https://aiswedenholmes7080246781.blob.core.windows.net/files/$Filename?sp=rw&st=2025-11-13T12:03:14Z&se=2025-11-13T20:18:14Z&spr=https&sv=2024-11-04&sr=c&sig=Rb0Aqy5Hg6G0PZiJV1M8cYY5MvELK8TXN8gxCu4xqjU%3D"
# Read the file content as a byte array
$FileContent = [System.IO.File]::ReadAllBytes("./$Filename")
# Upload the file to Azure Blob Storage
Invoke-RestMethod -Uri $SasUrl `
-Method Put `
-Body $FileContent `
-Headers @{
"x-ms-blob-type" = "BlockBlob"
"Content-Type" = "application/octet-stream"
}
# Download the file back from Azure Blob Storage
Invoke-RestMethod -Uri $SasUrl `
-Method Get `
-OutFile "new_$Filename.png"

Leave a comment