用于从 Azure blob 下载当前日期作为文件名的文件的 Powershell 脚本

Powershell script to download file with current date as filename from Azure blob

我需要 Powershell 脚本来从 Azure blob 下载当前日期作为文件名的文件,例如

app_09102021.txt
app_10102021.txt
app_11102021.txt

如果我 运行 11-10-2021 的脚本,文件 app_11102021.txt 应该可以下载。你能帮忙吗

我尝试了下面的代码,但在第 5 行 $latestblob

处出错
$container_name = 'XXXX'
$destination_path = 'D:\test\trial'
$Ctx = New-AzStorageContext $XXXX -StorageAccountKey $YYYYYYY
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#$latestBlob = Get-AzStorageBlob  -context $Ctx -Container trial|@{$app_$((Get-Date).tostring("yyyyMMdd")).txt}
# Just download that blob
Get-AzStorageBlobContent -Context $Ctx -Container $container_name -Blob $latestBlob.Name -Destination $destination_path 

I need Powershell script to download file with current date as filename from Azure blob

为此,我们可以按照@Theo

的建议使用以下 cmd
$container_name = 'test'
$destination_path = 'C:\Users\Desktop\test'
$Ctx = New-AzStorageContext 'name' -StorageAccountKey 'accesskey='
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$latestBlob = '*_{0:ddMMyyyy}.txt' -f (Get-Date) 

$bloblist = Get-AzStorageBlob -Container $container_name -Context $Ctx -Blob $latestBlob

在我的例子中,存储 blob 包含 3 个文件:

这是今天当前日期的输出: