我有一个通常可靠的(但在一台服务器上很麻烦) Azure Blob存储自动备份过程。我希望我的powershell脚本重新尝试上传,如果出于某种原因,它失败了。当ABS中还不存在文件时,我正在制作一个if语句(或do while循环)。如何捕捉Azure CLI调用AZ的结果?
我的测试结果如下:
if(az storage blob exists --account-name test --container-name test --name $name --sas-token $sasToken){
Echo "This is true"
}
else{
Echo "This is false"
}单独运行Azure CLI的输出是:
{
"exists": true
}我现在使用的语言太多了,语法总是略有不同
发布于 2022-09-07 18:12:40
捕获变量中Azure调用的结果,类似于$answer = az storage blob exists ...
然后,在您将答案从JSON转换出来之后,测试它的“存在”属性
if (($answer | ConvertFrom-Json).exists) {
Write-Host "blob '$name' exists"
}
else {
Write-Host "No blob called '$name' was found"
}https://stackoverflow.com/questions/73639797
复制相似问题