VMware Cloud Community
LarGo90
Contributor
Contributor
Jump to solution

vSphere6.0 PowerCLI Script problem to get esxhost information

Hi,


I'm struggling to get the ESXHost which the VM is running on with the script.

This is my script so far

get-view –viewtype VirtualMachine  |

select Name,

@{N="Powerstate"; E={$_.Guest.GuestState}}, `

@{N="CPUs"; E={$_.config.Hardware.NumCPU}}, `

@{N="RAM"; E={$_.config.Hardware.MemoryMB}}, `

@{N="IP Address"; E={$_.Guest.IPAddress}}, `

@{N="Operating System"; E={$_.config.GuestFullName}}, `

@{N=”Tools Version”; E={$_.config.tools.toolsVersion}}, `

@{N=”Tool Status”; E={$_.Guest.ToolsVersionStatus}}, `

@{N="Datastore"; E={$_.Summary.Config.VmPathName}}, `

@{N=”ESX Host”; E={Get-view -viewtype HostSystem | foreach {$_.name}}} |

Export-Csv -Path D:\_Auswertung\test.csv -NoTypeInformation -UseCulture

Right now it lists all the available esx hosts per VM, and I know that I have to let it know, that it should check inline with the first "get-view".

But I don't know how to and would like to get help from the community.

Thanks in advance,

Lars

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

@{N=”ESX Host”; E={Get-view -Id $_.Runtime.Host | Select -ExpandProperty Name}}


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

@{N=”ESX Host”; E={Get-view -Id $_.Runtime.Host | Select -ExpandProperty Name}}


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

LarGo90
Contributor
Contributor
Jump to solution

Thanks LucD - that works great.

Is there a way to get the Datastore aswell? The line for my Datastore reads out the *.vmx file information which is unique per vm and I cant easily filter it in Excel.

Thanks in advance!

Lars

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can extract the datastorename with some string manipulation.

Something like this

@{N="Datastore"; E={$_.Config.Files.VmPathName.Split(']')[0].Trimstart('[')}}, `


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

LarGo90
Contributor
Contributor
Jump to solution

You Sir just made my day. :smileyplus:

0 Kudos