Get vCenter name from “Get-View -Viewtype VirtualMachine”

This post was originally published on this site

Hey,

 

I’m having some issues with retrieving multiple pieces of information via powercli. We’re managing a couple of vCenters and for easier debuging, i’m creating a webpage that will display certain pieces of information regarding the environments. I’m currently having issues with getting the vCenter hostname with a oneliner via Get-View. So far I’ve got this:

 

 

Get-View -Viewtype VirtualMachine | Select-Object -Property name, @{N='CPU';E={$_.Config.Hardware.numCPU}}, @{N='Memory';E={$_.Config.Hardware.memoryMB}}, @{N='DNSHostname';E={$_.guest.hostname}}, @{N='IP';E={$_.Guest.Net.ipconfig.ipaddress.ipaddress -join '|'}}, @{N='VMHost';E={Get-View -Id $_.Runtime.Host -Property Name | Select -ExpandProperty Name}}

 

 

But I’m unable to get the vCenter hostname via ExtensionData (probably because I’m not reaching that property the correct way?).

 

Also, while we’re at it, the

 

@{N='VMHost';E={Get-View -Id $_.Runtime.Host -Property Name | Select -ExpandProperty Name}}

 

is also kinda slow. Is there any way to speed this up?

 

I’m running

 

PowerCLI Version

—————-

   VMware PowerCLI 11.5.0 build 14912921

—————

Component Versions

—————

   VMware Common PowerCLI Component 11.5 build 14898112

   VMware Cis Core PowerCLI Component PowerCLI Component 11.5 build 14898113

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.5 build 14899560

 

 

Thanks in advance!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.