VMware Cloud Community
shahb
Contributor
Contributor
Jump to solution

PowerCli script to generate report for VM and ESXi Model

Hi,

I'm trying generate a report for VMs for a DC which includes the OS, Cluster and the Make and Model of ESXi host but for some reason the ESXi info isn't coming through. Any help is greatly appreciated.

get-Datacenter "TEST" |

get-vm  |

where-object {$_.PowerState -eq “PoweredOn”} |

select Name, @{N="OS"; e={$_.Extensiondata.Guest.GuestFullName}},

@{N=’Cluster’;E={$_.VMHost.Parent}},

@{N=’Esxi Model’;E={Get-VMHost -VM $_.VM |select Model}}

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DZ1
Hot Shot
Hot Shot
Jump to solution

The VM has the properties for the host.  For your 'ESXi Model' information use $_.VMhost.Model, since $_  is the current pipeline information for the VM.  You did that for 'Cluster' section.

View solution in original post

0 Kudos
5 Replies
DZ1
Hot Shot
Hot Shot
Jump to solution

The VM has the properties for the host.  For your 'ESXi Model' information use $_.VMhost.Model, since $_  is the current pipeline information for the VM.  You did that for 'Cluster' section.

0 Kudos
shahb
Contributor
Contributor
Jump to solution

Thank you DZ1.  You rock.

One question -

How do I find what properties are available ?  $_.VMhost.<Property> So I can refer to it. Also are there properties for other object as well which can be used ? like $_.VM or Datacenter etc.

Thanks a lot.

0 Kudos
DZ1
Hot Shot
Hot Shot
Jump to solution

You could just save a VM as a variable, and then just go through and see what the properties are.  Some 3rd party ISEs have variable explorers that let you expand variable properties like a tree.

Try something like this $vmName = Get-VM 'Name of your VM'

Then, just type $vmName | format-list * or you could use $vmName | get-member

Either of those would show you the properties.  You would see that a property is VMHost, and then you could try something like $vmName.VMhost | format-list * and keep going, to you see the properties for other items.

If your ISE has intellisense, once you type $vmName. (that's a dot at the end), the intellisense may just pop-up the properties that you can see.  The easiest is to use an ISE that has a variable explorer, I know PowerGUI has one.  Unfortunately, PowerGUI has not had a new version in some time, but it still works, and it's free.

I purchased a license for ISE-Steroids, and it bascially beefs up the default PowerShell ISE, and it has a variable explorer.  Hope that helps.

0 Kudos
shahb
Contributor
Contributor
Jump to solution

Excellent. Thank you DZ1.

0 Kudos
shahb
Contributor
Contributor
Jump to solution

Hi DZ1

Sorry to bug again . This is my last question.. I'm struggling get the datacenter and datastore property info.

for example -

get-vm  | where-object {$_.PowerState -eq “PoweredOn”} | select Name, @{N="OS"; e={$_.Extensiondata.Guest.GuestFullName}}, @{N=’Cluster’;E={$_.VMHost.Parent}},@{N=’Esxi Model’;E={$_.VMHost.Model}}

I can't find a way to do this with one-liner to include the datacenter and datastore for the VM. I can do following and it works

@{N="Datacenter";E={Get-Datacenter -VM $_.VM}}


But for this to work, it must be in a separate line due to where-object {$_.PowerState -eq “PoweredOn”}.


I'm looking for something like property to get the DataCenter and datastore (the one I get with property for datastore is not the real name)


Thanks for all your help.

0 Kudos