我正在嘗試創建一個Get-annotations用于檢索一些自定義值的報告,實際上它作業正常,但我只能在同一行的報告中插入 1 個值,下面是我僅對 1 個值所做的操作,是否有一些語法可以使用不是這樣Get-Annotation -Name value1, value2, value3
$AW= foreach ($vmsowner in $VMsOwners)
{
$VMlisted = $vmsowner.objectname
get-vm $VMlisted | Get-Annotation -Name "Application Owner"| select @{label="VM";expression={$_.AnnotatedEntity}}, @{label="Application Owner";expression={$_.Value}}
}
$AW | ConvertTo-Csv -NoTypeInformation | Out-File -FilePath $FilenameOwners
uj5u.com熱心網友回復:
Get-Annotation 在計算的屬性運算式中呼叫:
Get-VM |Select @{Name='VM';Expression={$_}},@{Name='Application Owner';Expression={($_ |Get-Annotation -Name 'Application Owner').Value}},,@{Name='Some other tag';Expression={($_ |Get-Annotation -Name 'Some other tag').Value}}
對于所有這些計算出的屬性定義,它可能很快變得不可讀,但您可以從注釋名稱串列中生成它們:
# define annotations your want to retrieve per vm
$annotations = 'Application Owner', 'Data Owner', 'Some other tag', 'Something else completely'
# generate calculated property definitions
$properties = @(
@{Name='VM';Expression={$_}}
$annotations |ForEach-Object {
$annotationName = $_
@{Name=$_;Expression=[scriptblock]::Create("`$(`$_ | Get-Annotation -Name '$_').Value")}
}
)
# fetch VMs and select properties
Get-VM |Select $properties
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370376.html
