25 February, 2022
Upload to Azure Storage Blob from PowerShell
A quick script to upload content to Azure Storage Blob from pure PowerShell (without needing the Azure PowerShell module):
$file_name = "garbage.txt"
$storage_account = "std85e4286"
$container = "temp"
$sas = "sv=2020-08-04&ss=b&srt=sco&sp=rwdlacitfx&se=2022-02-24T19:30:00Z&st=2022-02-24T19:25:11Z&spr=https&sig=BwOA2AFlsOvVdATxr6MJEKzH1QPvFBWcHZHO9DhF4MU%3D"
$url = "https://{0}.blob.core.windows.net/{1}/{2}?{3}" -f $storage_account, $container, $file_name, $sas
$headers = @{
'x-ms-blob-type' = "BlockBlob"
'x-ms-blob-content-disposition' = "attachment; filename=`"{0}`"" -f $file_name
'x-ms-meta-hostname' = $env:COMPUTERNAME
}
Invoke-WebRequest $url -Infile $file_name -Method 'PUT' -Headers $headers