【问题标题】:Azure automation, PowerShell to fetch a file in public blob containerAzure 自动化,PowerShell 来获取公共 blob 容器中的文件
【发布时间】:2022-10-07 13:08:20
【问题描述】:
我有一个公共文件共享存储,我想问一下。是否可以一次性下载和安装,比如是否有为此目的的环境,或者我需要使用目标文件夹下载,然后执行我需要安装的字体的安装?
另外,pnp-connect 是否可以与公共 azure 存储文件夹一起使用?
还是仅适用于共享点?
如果没有,会
Invoke-WebRequest -Uri $uri -OutFile $filePath
... 作为我的公共 Azure 存储的连接工作?
如果有人有想法,请提前感谢:)
标签:
azure
powershell
installation
download
storage
【解决方案1】:
是否可以一次性下载和安装,例如是否有为此目的的环境,或者我需要使用目标文件夹下载,然后执行我需要安装的字体的安装?
AFAIK,在 blob 容器中,我们可以保留文件,但我们不能在 blob 中安装任何可执行文件。
利用获取 AzureStorageBlobContent获取 blob 的内容。
解决方法
$CName = '<ContainerName>'
$downPath = '<Path to download>'
$StorageConnString = '<Storage account Connection String>'
#collect storage accout details
$getStorageAcc = New-AzureStorageContext -ConnectionString $StorageConnString
#Get Blob details
$getBlobs = Get-AzureStorageBlob -Container $CName -Context $getStorageAcc
#Download blob
Get-AzureStorageBlobContent `
-Container $CName -Blob $getBlobs.Name -Destination $downPath `
-Context $getStorageAcc
# using storage account uri you can download the blob files using "Invoke-WebRequest" or follow below
$BlobFileUri = 'https://<StorageAccountName>.blob.core.windows.net/<ContainerName>/<YourFiletoDownload>.txt'
#Generate SAS URI from portal and Add here
$Sasuri = '<SAS URI>'
#Download blob using SAS URI
$URI = "$BlobFileUri$Sasuri"
(New-Object System.Net.WebClient).DownloadFile($URI, $downPath)
结果