我需要在所有租户设备上运行脚本,以便将文件上传到Azure容器中
我看到这个脚本PowerShell Basics: How to Upload Files to Azure Storage,但我不能管理,使其工作。
我创建了一个SAS密钥,我尝试了帐户密钥和用户委派密钥
这是我的代码
#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
}
1条答案
按热度按时间yyyllmsg1#
要使用SAS令牌发送文件,您可以使用
New-AzStorageContext
和-SasToken
参数以及Set-AzStorageBlobContent
示例:
参见:
https://stackoverflow.com/a/69031205/194717
文件:
https://learn.microsoft.com/en-us/powershell/module/az.storage/set-azstorageblobcontent?view=azps-9.5.0
https://learn.microsoft.com/en-us/powershell/module/az.storage/new-azstoragecontext?view=azps-9.5.0#example-9-create-a-context-by-using-an-sas-token
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-powershell#upload-blobs-to-the-container