VMware Cloud Community
paullee92
Enthusiast
Enthusiast

Grab Annotation details

Hi Team,

I require to grab a number of specific annotation details from the VM.

I Managed to grab below detail About Business Owner:

Get-VM  | Get-Annotation | Where-Object {$_.Name -eq "Business Owner"}

Result:

I getting Values for Business Owner

How may i add further require filter information such as "Environment", "OS Type", and "Server Type" together with Business Owner 

Im looking for the Result to be shown as per below:

The VM name just display one time, Follow by Entity and its value

Annotated     Entity                         Name Value
---------------   ----                               -----
VM Name       Business Owner
                       OS Type
                       Environtment
                       Server Type

0 Kudos
3 Replies
LucD
Leadership
Leadership

You mean something like this?

Get-VM -PipelineVariable vm |
ForEach-Object -Process {
  $first = $true
  Get-Annotation -Entity $vm |
  ForEach-Object -Process {
    if ($first) {
      $vmname = $vm.Name
      $first = $false
    } else {
      $vmname = ''
    }
    $_ | Select-Object @{N = 'VM'; E = { $vmname } }, Name, Value
  }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
paullee92
Enthusiast
Enthusiast

yes like this, but i want only display the Business Owner, Environment, OS Type, Server Type for each of the VM

0 Kudos
LucD
Leadership
Leadership

Then restrict the Get-Annotation to specific Custom Attributes

$ca = Get-Customattribute -Name 'Business Owner','Environment','OS Type','Server Type'

Get-VM -PipelineVariable vm |
ForEach-Object -Process {
  $first = $true
  Get-Annotation -Entity $vm -CustomAttribute $ca |
  ForEach-Object -Process {
    if ($first) {
      $vmname = $vm.Name
      $first = $false
    } else {
      $vmname = ''
    }
    $_ | Select-Object @{N = 'VM'; E = { $vmname } }, Name, Value
  }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos