VMware Cloud Community
lynwen
Contributor
Contributor

PowerCli Report on Custom Annotations

New to PowerCli.

My problem is attempting to create a report on selected Virtual Machines that have a specific value in a custom attribute I've created. 

I have created a Custom Attribute named  PowerDownStage of type 'Virtual Machine', the VMs have entries valued between 1 and 5.

I need to get a list of VMs with, for example, value of 3 exported into a csv file.

The command I've created (below) does return a list however, it returns a list of all VMs and the PowerDownStage value and not filtered by PowerDownStage - eq "3"

Grateful for any advice please?

get-VM | get-annotation -CustomAttribute "PowerDownStage" |

select AnnotatedEntity,Value

@{N="Value";E={$key = $_.AvailableField | where {$_.PowerDownStage -eq "3"} | Select -ExpandProperty Key

  $_.CustomValue | where {$_.Key -eq $key} | Select -ExpandProperty Value}}

 

4 Replies
LucD
Leadership
Leadership

Try something like this

Get-VM | Get-Annotation -CustomAttribute "PowerDownStage" |

where {$_.Value -eq 3} |

select @{N='VM';E={$_.AnnotatedEntity}},Value |

Export-Csv report.csv -NoTypeInformation -UseCulture


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

lynwen
Contributor
Contributor

This works great.  All I need to do now is to add a value to "PowerDownStage" attribute for each VM listed in an excel spreadsheet.

Thanks for your help.

Lynwen

0 Kudos
Bean78
Contributor
Contributor

Can you help me with the script to generate custom attributes report for ESXi servers managed in a vCenter.
0 Kudos
LucD
Leadership
Leadership

You mean like this?

Get-VMHost | Get-Annotation |

select @{N='VMHost';E={$_.AnnotatedEntity}},Name,Value |

Export-Csv report.csv -NoTypeInformation -UseCulture


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

0 Kudos