VMware Cloud Community
Gaprofitt17
Enthusiast
Enthusiast

Custom attributes report from vCenter

 

Hi,

I'm trying to report on the following per vCenter:

VM name, all custom attribute fields including fields with no values. I've found some good examples in the community on interjecting new values but not on just reporting.  Is there something more robust than below? Pulling from vCenter DB, etc..

Get-VM | Select Name -ExpandProperty CustomFields

 

 

Thanks..

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

What do you mean by "...more robust"?
Is that line failing, incomplete, or producing errors?


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

Reply
0 Kudos
Gaprofitt17
Enthusiast
Enthusiast

 

It runs successfully, but we are also using vCloud Director with meta data/tags.  It looks like these are not passed into vCenter.  Is there a mechanism to pass them or at least query the data from vCD?  The cmdlets for vCloud Director look pretty limiting.

Reply
0 Kudos
LucD
Leadership
Leadership

Since your question is obviously about vCD I moved the thread to that community.


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

Reply
0 Kudos
Gaprofitt17
Enthusiast
Enthusiast

I'm trying to do the following:

Get a report of all associated Metadata with each VM in vCloud Director..  Ideally i'd have vorg name, vdc, vapp, and vm name and associated metadata for just the VM.

$vmv = Get-CIVM | Sort-Object -Property Name
Foreach ($vm In $vmv) { $Metadata = $vm.ExtensionData.GetMetadata() | Export-CSV -path c:\scripts\test1.csv }
 
You cannot call a method on a null-valued expression.
 
Figure out how to update an existing attribute/value with the correct value for a given VM..

Thanks in advance..
 
 
Reply
0 Kudos
Gaprofitt17
Enthusiast
Enthusiast

Ok, i'm close..

Connect-CIServer -Server https://servername
$vmv = Get-CIVM -name testvmname

Foreach ($vm in $vmv) {

$Metadata = $vm.ExtensionData.GetMetadata()

$MetaValue1= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"owner_name")].TypedValue.Value
$MetaValue2= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"referential_id")].TypedValue.Value
$MetaValue3= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"template_os_version")].TypedValue.Value
$MetaValue4= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"class_of_data")].TypedValue.Value
$MetaValue5= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"service_offering")].TypedValue.Value
$MetaValue6= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"app_code")].TypedValue.Value
$MetaValue7= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"server_role")].TypedValue.Value
$MetaValue8= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"template_os_name")].TypedValue.Value
$MetaValue9= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"business_unit")].TypedValue.Value
$MetaValue10= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"env")].TypedValue.Value
$MetaValue11= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"cost_code")].TypedValue.Value
$MetaValue12= $Metadata.MetadataEntry[[array]::indexof($Metadata.MetadataEntry.Key,"cmdb_ci_service_technical")].TypedValue.Value

Write-Host $vm + $MetaValue1 + $MetaValue2 +$MetaValue3 + $MetaValue4 + $MetaValue5 + $MetaValue6 + $MetaValue6 + $MetaValue7
 
 
How do I get the data in a CSV with the VM names, $MetaValue1, 2, 3 etc with the corresponding values and keys?  Also for NULL it blows up..
Reply
0 Kudos