kunaludapi
Expert
Expert

Is there any powercli command or script available from which i can pull vcenter version and esxi host belogs to which vcenter server?

Is there any powercli command or script available from which i can pull vcenter version and esxi host belogs to which vcenter server?

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Tags (3)
9 Replies
LucD
Leadership
Leadership

Not sure if are looking for the ESXi version or the vCenter version.

Get-VMHost  |
Select Name,Version,@{N="vCenter";E={$_.ExtensionData.CLient.ServiceUrl.Split('/')[2]}}


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

kunaludapi
Expert
Expert

Many Thanks LucD,

Perfect, I tried it and able to pull vcenter name that esxi host belongs to.

I need to pull vCenter version, not esxi server version.

Regards,

Kunal udapi

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
LucD
Leadership
Leadership

Try something like this

foreach($esx in Get-VMHost){
 
$esx | Select Name,
 
@{N="vCenter";E={$_.ExtensionData.CLient.ServiceUrl.Split('/')[2]}},
 
@{N="vCenter version";E={
     
$global:DefaultVIServers |
     
where {$_.Name -eq ($esx.ExtensionData.CLient.ServiceUrl.Split('/')[2])} |
     
%{"$($_.Version) build $($_.Build)"}
    }}
}


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

Hi LucD,

It will be more helpful if you can please clarify this  'split line'

[vSphere PowerCLI] C:\> $h.ExtensionData.Client.ServiceUrl

https://vc01/sdk

So while spliting, $h.ExtensionData.Client.ServiceUrl.split('/')[2], how VC name becomes 3 rd value in the array.

1st value is https and 2nd value shows "blank"

If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos
LucD
Leadership
Leadership

Sure, the URL looks something like this "http://server/whatever"

By splitting on the '/' character, you will get an array of values:

1 - "http"

2 - empty string (there is nothing between the 2 slashes

3 - "server"

4 - ...

We want the servername, and since a PowerShell arrays start indexing from 0, we need to use the index 2 to get it.


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

0 Kudos
K_A1
Contributor
Contributor

You can get the VC version with  $global:DefaultVIServer.ExtensionData.Content.About after you connect to VC

0 Kudos
justinbennett
Enthusiast
Enthusiast

I liked this. I changed it a little so you can capture the output to a $variable and added the ESXi's version and build too.

$myESXiHosts = Get-VMHost | %{ $_ | Select Name,

  @{N="ESXi Version";E={"$($_.Version) build $($_.Build)"}},

  @{N="vCenter";E={$_.ExtensionData.CLient.ServiceUrl.Split('/')[2]}},

  @{N="vCenter version";E={

      $global:DefaultVIServers |

      where {$_.Name -eq ($_.ExtensionData.CLient.ServiceUrl.Split('/')[2])} |

      %{"$($_.Version) build $($_.Build)"}

    }}

}

PowerCLI/Get-ESXi-Hosts-and-vCenter-Builds.ps1 at master · cajeeper/PowerCLI · GitHub

0 Kudos
tdubb123
Expert
Expert

Hi

Is there a way to get the output of the vcenter name as well with

$global:Defausltviservers.extensiondata.content.about | ft -auto

Screen Shot 2017-06-21 at 7.26.03 AM.png

0 Kudos
tdubb123
Expert
Expert

ok I think I got it.

Screen Shot 2017-06-21 at 7.47.20 AM.png

0 Kudos