PowerCLI

Expand all | Collapse all

Get vCenter and ESXi Host Version and Build numbers

  • 1.  Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 03, 2025 05:28 AM

    I need to extract vCenter and ESXi host versions and builds using PowerCLI (or PowerShell if possible) then output to a csv or a table to save and add to a master spreadsheet. Apologies, i am new to PowerCLI and need help to achieve this. I would be grateful if anybody could provide me with a script to achieve this. Many thanks



    ------------------------------
    PS
    ------------------------------


  • 2.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 03, 2025 05:29 AM

    Try something like this

    $global:defaultVIServers | ForEach-Object -Process {
      $vc = $_
      Get-VMHost -Server $vc |
      ForEach-Object -Process {
        New-Object -TypeName PSObject -Property ([ordered]@{
            vCenter = $vc.Name
            vCenterVersion = $vc.Version
            vCenterBuild = $vc.Build
            VMHost = $_.Name
            VMHostVersion = $_.Version
            VMHostBuild = $_.Build
          })
      }
    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
    


    ------------------------------


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


    ------------------------------



  • 3.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 03, 2025 06:23 AM
    Edited by Ph Sp Feb 03, 2025 06:25 AM

    Thanks LucD, much appreciated.

    I only need to log into one vCenter at a time so would this do the trick:

    PowerCLI C:\> Connect-VIServer -Server ip address -Protocol https -User username -Password pass | ForEach-Object -Process {
      $vc = $_
      Get-VMHost -Server $vc |
      ForEach-Object -Process {
        New-Object -TypeName PSObject -Property ([ordered]@{
            vCenter = $vc.Name
            vCenterVersion = $vc.Version
            vCenterBuild = $vc.Build
            VMHost = $_.Name
            VMHostVersion = $_.Version
            VMHostBuild = $_.Build
          })
      }
    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture




  • 4.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 03, 2025 06:37 AM

    That should work



    ------------------------------


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


    ------------------------------



  • 5.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 03, 2025 09:50 AM

    Thanks again LucD

    It appears to be missing the vCenter Appliance info in the csv, but host and other info is correct. Any ideas please?




  • 6.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 03, 2025 10:58 AM

    Works for me.
    Check what object, with which properties, the Connect-VIServer cmdlet returns

    Connect-VIServer -Server ip address -Protocol https -User username -Password pass |
    Select *


    ------------------------------


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


    ------------------------------



  • 7.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 04, 2025 04:39 AM

    I get this when running 

    Connect-VIServer -Server ip address -Protocol https -User username -Password pass |
    Select *



    Displays the vCenter Version and Build but not in the csv




  • 8.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 04, 2025 04:52 AM

    It must be how you run the code from the prompt.
    How do you run the code I provided?

    Do you run that script from the prompt?
    Normally you save such scripts in a .ps1 file and run from there.



    ------------------------------


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


    ------------------------------



  • 9.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 04, 2025 05:08 AM

    Yes, i have got it now. First i run Connect-VIServer -Server ipaddress -Protocol https -User  -Password  | Select * then i run

    Connect-VIServer -Server ipaddress -Protocol https -User  -Password  | ForEach-Object -Process {
      $vc = $_
      Get-VMHost -Server $vc |
      ForEach-Object -Process {
        New-Object -TypeName PSObject -Property ([ordered]@{
            vCenter = $vc.Name
            vCenterVersion = $vc.Version
            vCenterBuild = $vc.Build
            VMHost = $_.Name
            VMHostVersion = $_.Version
            VMHostBuild = $_.Build
          })
      }
    } | Export-Csv -Path .\filename.csv -NoTypeInformation -UseCulture

    This then gives me the vCenter version and build.


    Also, if i want to get all VMs into the csv too, please could you add to the script the commands to do this. 

    Thanks for all of your help with this. It is very much appreciated.




  • 10.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 04, 2025 05:14 AM

    So a script that gives me vCenter version and build, host version and build and all VMs with version of VMTools if possible. Many thanks




  • 11.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 04, 2025 06:06 AM
    Edited by LucD Feb 04, 2025 06:12 AM

    How would you present that in a CSV file?
    There will be a lot of redundant data in there.

    $global:defaultVIServers | ForEach-Object -Process {
      $vc = $_
      Get-VMHost -Server $vc |
      ForEach-Object -Process {
        Get-VM -Location $_ |
        ForEach-Object -Process {
        New-Object -TypeName PSObject -Property ([ordered]@{
            vCenter = $vc.Name
            vCenterVersion = $vc.Version
            vCenterBuild = $vc.Build
            VMHost = $_.VMHost.Name
            VMHostVersion = $_.VMHost.Version
            VMHostBuild = $_.VMHost.Build
            VM = $_.Name
            ToolsVersion = $_.Guest.ToolsVersion
          })
      }
    }
    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture



  • 12.  RE: Get vCenter and ESXi Host Version and Build numbers

    Posted Feb 04, 2025 06:20 AM

    I will run and check the results LucD. Thak you