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
Try like this
@{N=”ESX Host”; E={Get-view -Id $_.Runtime.Host | Select -ExpandProperty Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
@{N=”ESX Host”; E={Get-view -Id $_.Runtime.Host | Select -ExpandProperty Name}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
You Sir just made my day. :smileyplus: