I need to run a script on all my tenants devices to upload a file into an Azure Container
I saw this Script PowerShell Basics: How to Upload Files to Azure Storage but i can't manage to make it work.
I create a SAS key, i tried both Account key and User Delegation key
Here's my code
#Variable
$FolderPath= "D:\BatteryReport"
#Check if Folder exists
If(!(Test-Path -Path $FolderPath))
{
New-Item -ItemType Directory -Path $FolderPath
Write-Host "New folder created successfully!" -f Green
}
Else
{
Write-Host "Folder already exists!" -f Yellow
}
powercfg /batteryreport /output D:\BatteryReport\BatteryReport_$(hostname).html
Install-Module -Name Az -AllowClobber
$StorageURL = "https://mytenant.blob.core.windows.net/pub"
$FileName = "BatteryReport_$(hostname).html"
$SASToken = "mySASkey"
$blobUploadParams = @{
URI = "{0}/{1}?{2}" -f $StorageURL, $FileName, $SASToken
Method = "PUT"
Headers = @{
'x-ms-blob-type' = "BlockBlob"
'x-ms-blob-content-disposition' = "attachment; filename=`"{0}`"" -f $FileName
'x-ms-meta-m1' = 'v1'
'x-ms-meta-m2' = 'v2'
}
Body = $Content
Infile = $FileToUpload
}