Hello
I have below custom attributes in vCenter
At times folks create VM & forget to updates these
I have code like below
Get-VM $($line.name) |Get-Annotation -CustomAttribute "OS"
But i would like to filter t9o get VM names , only if the value is blank for any said custom attributes
Please suggest
Thanks
You could do something like this
Get-VM |
where{(Get-Annotation -Entity $_ -CustomAttribute OS).Value -eq ''} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That requires a slightly different Where-clause.
Get-VM |
Where{(Get-Annotation -Entity $_ -Customattribute 'OS', 'LOB').Value.Foreach{ $_ -eq '' } -contains $true} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
Get-VM |
where{(Get-Annotation -Entity $_ -CustomAttribute OS).Value -eq ''} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ah thanks @LucD i was trying like below was not working
Get-VMHost -location xxx | Get-VM |Get-Annotation -CustomAttribute "OS" | Where-Object { $_.OS -notlike '' }
Can i add other attributes in code like
where{(Get-Annotation -Entity $_ -CustomAttribute OS).Value -eq ''} or where{(Get-Annotation -Entity $_ -CustomAttribute LOB).Value -eq ''}
etc ?
You can add multiple customa ttributes on the CustomAttribute parameter.
The following will list the VM if at least one of the custom attributes does not have a value
Get-VM |
Where{(Get-Annotation -Entity $_ -Customattribute 'OS', 'LOB').Value.Foreach{ $_ -ne '' } -notcontains $true} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD thanks for the reply
I tested with 2 vms , both are power on
One has only OS custom attribute set
Other VM has none set
But below code only reported the one which has all blank .. so looks like the code used "AND" vs "OR"
In my case i need names of all vms where either of the attributes is not set ( ie if any vm has both attributes set they are good & i do not care about them )
Please suggest
That requires a slightly different Where-clause.
Get-VM |
Where{(Get-Annotation -Entity $_ -Customattribute 'OS', 'LOB').Value.Foreach{ $_ -eq '' } -contains $true} |
Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference