VMware Cloud Community
trav3ll3r
Contributor
Contributor
Jump to solution

Export VM info

Long time lurker and my first post in VMware forums! Woo Hoo

In preparation for a storage migration project, I setup annotations for all VMs in the datacenter to indicate what Environment, Metallic, App Tier they belong to.

So now, while I can list VM information based on their properties obtained from Get-View, I cannot figure out how to list out data from the Annotations I set up .

$vms = Get-Datastore | where {$_.Name -like "*Tier2*"} | Get-VM

foreach($vm in $vms){

Get-VM -Name $vm | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, @{N="ESX Host";E={Get-VMHost -VM $_}},@{N="Datastore";E={Get-Datastore -VM $_}},@{N="IP";E={$_.ExtensionData.Summary.Guest.IpAddress}},@{N="PowerState";E={$_.ExtensionData.runtime.powerstate}} | ft -AutoSize

The script above gives me an output as under

Name     Cluster     ESX Host     Datastore     IP     PowerState

How can I add information from annotations I set up for my VMs so that the output looks like the following:

Name     Cluster     ESX Host     Datastore     IP     PowerState     Environment     Metallic     AppTier

Thank you very much!

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Welcome!

Try like this

Get-Datastore | where {$_.Name -like "*Tier2*"} | Get-VM |

Select Name,

    @{N="Cluster";E={Get-Cluster -VM $_}},

    @{N="ESX Host";E={Get-VMHost -VM $_}},

    @{N="Datastore";E={Get-Datastore -VM $_}},

    @{N="IP";E={$_.ExtensionData.Summary.Guest.IpAddress}},

    @{N="PowerState";E={$_.ExtensionData.runtime.powerstate}},

    @{N='Environment';E={Get-Annotation -Entity $_ -Name Environment | select -ExpandProperty Value}},

    @{N='Metalic';E={Get-Annotation -Entity $_ -Name Metalic | select -ExpandProperty Value}},

    @{N='AppTier';E={Get-Annotation -Entity $_ -Name AppTier | select -ExpandProperty Value}}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Welcome!

Try like this

Get-Datastore | where {$_.Name -like "*Tier2*"} | Get-VM |

Select Name,

    @{N="Cluster";E={Get-Cluster -VM $_}},

    @{N="ESX Host";E={Get-VMHost -VM $_}},

    @{N="Datastore";E={Get-Datastore -VM $_}},

    @{N="IP";E={$_.ExtensionData.Summary.Guest.IpAddress}},

    @{N="PowerState";E={$_.ExtensionData.runtime.powerstate}},

    @{N='Environment';E={Get-Annotation -Entity $_ -Name Environment | select -ExpandProperty Value}},

    @{N='Metalic';E={Get-Annotation -Entity $_ -Name Metalic | select -ExpandProperty Value}},

    @{N='AppTier';E={Get-Annotation -Entity $_ -Name AppTier | select -ExpandProperty Value}}


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

trav3ll3r
Contributor
Contributor
Jump to solution

Thank you, Luc. This gave me exactly what I was looking for.

0 Kudos