我正在使用以下代码访问和检索 Azure 中的 blob 属性。我想让这个函数通用,这样我就可以用任何“属性”名称调用它,而不是像下面硬编码的那样只检索“IsServerEncrypted”属性:
function GetBlobProperty {
Param(
[parameter(Mandatory = $true)] [String] $blobProperty, # <<<<<=I want to retrieve any property
[parameter(Mandatory = $true)] [String] $storageAccountName,
[parameter(Mandatory = $false)] [String] $storageAccountKey,
[parameter(Mandatory = $false)] [String] $containerName,
[parameter(Mandatory = $false)] [String] $blobName
)
$ctx = GetStorageContext $storageAccountName $storageAccountKey
$Blobs = Get-AzStorageBlob -Container $containerName -Context $ctx
$retValue = ""
ForEach ($Blob in $Blobs){
#Write-Host $Blob.Name
if($Blob.Name.IndexOf($blobName) -ge 0)
{
Write-Host $Blob.Name
$retValue = $Blob.ICloudBlob.Properties.IsServerEncrypted #I want to pass $blobProperty here
break;
}
}
return $retValue
}
谢谢!