Automation

 View Only
Expand all | Collapse all

Possible to export our vCenter Inventory to CSV?

  • 1.  Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 02:15 PM

    Hello,

    We have 48 hosts in our vCenter across 4 Clusters.

    Is it possible to export this inventory to csv so it it includes attributes like:

    Cluster name,Host name, Hypervisor (for example VMware ESXi, 7.0.3, 19193900), model, Processor Type, Logical Processors, Nics, Serial Number, state, status, ha, uptime, version, no vms.

    Basically a one stop table, I am to then push to Influxdb or Grafana.

     

    Thanks



  • 2.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 02:21 PM

    If you do a search in this community you should find solutions for retrieving most, if not all, of these properties.



  • 3.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 02:35 PM

    Searching now, thanks.



  • 4.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 02:39 PM

    If you get stuck on one or more of those properties, let us know.



  • 5.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 03:45 PM

    I'm managed to find 2 scripts that work independently, but I'm not sure how to merge into one table. I still need to find the other attributes, but getting closer:

    Get-VMHost | select name, connectionstate, powerstate, numcpu, version | Export-Csv C:\vmware\powercli\reports\vmhostinfov1.csv -NoTypeInformation

    and

    foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
    
        $esxcli.hardware.platform.get.Invoke() |
    
        Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,ProductName,SerialNumber
    
    }


  • 6.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 04:01 PM

    You could do something like this to combine them

    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $platform = $esxcli.hardware.platform.get.Invoke()
        [PSCustomObject]@{
            Name = $esx.Name
            Cluster = (Get-Cluster -VMHost $esx).Name
            ConnectionState = $esx.ConnectionState
            PowerState = $esx.PowerState
            NumCPU = $esx.NumCpu
            Version = $esx.Version
            VendorName = $platform.VendorName
            ProductName = $platform.ProductName
            SerialNumber = $platform.SerialNumber
        }
    } | Export-Csv C:\vmware\powercli\reports\vmhostinfov1.csv -NoTypeInformation -UseCulture
    


  • 7.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 05:21 PM

    Oh yes this is wonderful!

    Do you know where or how I can get the other attributes, I'm sure there is a long list of other nice attributes to add to the table that I can source or lookup, for example:

    No. Nics, status, ha, uptime, no vms, Processor Type, bios version, total memory, processor speed, processor sockets, processor cores per socket, hyperthreading status, etc.

    Just looking through vCenter.

     
     


  • 8.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 05:55 PM

    Like I said, most of these properties are already discussed in this community.

    Just for info, I added a few more, so you can check how it is done.

    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        $esxcli = Get-EsxCli -VMHost $esx -V2
        $platform = $esxcli.hardware.platform.get.Invoke()
        $cpu = $esxcli.hardware.cpu.global.get.Invoke()
        [PSCustomObject]@{
            Name = $esx.Name
            Cluster = (Get-Cluster -VMHost $esx).Name
            ConnectionState = $esx.ConnectionState
            PowerState = $esx.PowerState
            NumCPU = $esx.NumCpu
            Version = $esx.Version
            VendorName = $platform.VendorName
            ProductName = $platform.ProductName
            SerialNumber = $platform.SerialNumber
            NoNic = $esxcli.network.nic.list.Invoke().Count
            Status = $esx.State
            HA = $esx.ExtensionData.Summary.Runtime.DasHostState.State
            Uptime = ((Get-Date) - $esx.ExtensionData.Runtime.BootTime).ToString("dd' days 'hh' hours 'mm' minutes 'ss' seconds'")
            NoVM = $esx.ExtensionData.VM.Count
            BIOSVersion = $esx.ExtensionData.Hardware.BiosInfo.BiosVersion
            BIOSVendor = $esx.ExtensionData.Hardware.BiosInfo.Vendor
            BIOSReleaseDate = $esx.ExtensionData.Hardware.BiosInfo.ReleaseDate
            Processor = $esx.ExtensionData.Hardware.CpuPkg[0].Description
            MemoryGB = $esx.MemoryTotalGB
            ProcSpeedGhz = [math]::Round($esx.ExtensionData.Hardware.CpuInfo.Hz/(1000*1000*1000),1)
            ProcSockets = $cpu.CPUPackages
            ProcCoresPerSocket = $cpu.CPUCores / $cpu.CPUPackages
            HTStatus = if($cpu.HyperthreadingActive){'Active'}else{'Not Active'}
        }
    } | Export-Csv C:\vmware\powercli\reports\vmhostinfov1.csv -NoTypeInformation -UseCulture
    


  • 9.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 08, 2022 02:31 PM

    This is totally unbelievable, thank you!

    I'm not sure what other attributes I'm missing that could be useful, but so much info pulled.



  • 10.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 16, 2022 05:24 PM

    Just one last thing, is it possible to add the EVC mode in that list too?



  • 11.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 16, 2022 05:27 PM

    You can add a property

    EVCMode = (Get-Cluster -VMHost $esx).EVCMode


  • 12.  RE: Possible to export our vCenter Inventory to CSV?

    Posted Mar 07, 2022 03:07 PM

     

    Using this I tried myself, I just need to get the rest of the attributes:

    Get-VMHost | select name, connectionstate, powerstate, numcpu, version | Export-Csv C:\vmware\powercli\reports\vmhostinfov1.csv -NoTypeInformation