VMware Cloud Community
dcoz
Hot Shot
Hot Shot
Jump to solution

Vcenter inventory

Hi guys,

I am trying to create an inventory of all the ESX hosts and build numbers for my vCenter.

I am trying to have the output in the below format in an excel spreadsheet.

datacenter

     I

     I------>Cluster

                    I

                    I------->hosts name and build numbers

I have tried several times to get this format without any joy. Any help on how to start this to get this output would be great.

Thanks

Dougie

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Dougie,

the next PowerCLI will create the desired report and will put the information in a .csv file called ESXinventory.csv. If you open this file in Excel, it will have the layout you want.

Get-Datacenter | `
  Sort-Object -Property Name | `
  ForEach-Object {
    $Datacenter = $_
    $Report =  "" | Select-Object Datacenter, Cluster, VMHost, Build
    $Report.Datacenter = $Datacenter.Name
    $Report
    $Datacenter | `
      Get-Cluster | `
      Sort-Object -Property Name | `
      ForEach-Object {
        $Cluster = $_        
        $Report =  "" | Select-Object Datacenter, Cluster, VMHost, Build
        $Report.Cluster = $Cluster.Name
        $Report
        $Cluster | `
          Get-VMHost | `
          Sort-Object -Property Name | `
          ForEach-Object {
            $VMHost = $_
            $Report =  "" | Select-Object Datacenter, Cluster, VMHost, Build
            $Report.VMHost = $VMHost.Name
            $Report.Build = $VMHost.Build
            $Report
          }
      }
  } | Export-Csv -Path ESXinventory.csv -NoTypeInformation -UseCulture


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Dougie,

the next PowerCLI will create the desired report and will put the information in a .csv file called ESXinventory.csv. If you open this file in Excel, it will have the layout you want.

Get-Datacenter | `
  Sort-Object -Property Name | `
  ForEach-Object {
    $Datacenter = $_
    $Report =  "" | Select-Object Datacenter, Cluster, VMHost, Build
    $Report.Datacenter = $Datacenter.Name
    $Report
    $Datacenter | `
      Get-Cluster | `
      Sort-Object -Property Name | `
      ForEach-Object {
        $Cluster = $_        
        $Report =  "" | Select-Object Datacenter, Cluster, VMHost, Build
        $Report.Cluster = $Cluster.Name
        $Report
        $Cluster | `
          Get-VMHost | `
          Sort-Object -Property Name | `
          ForEach-Object {
            $VMHost = $_
            $Report =  "" | Select-Object Datacenter, Cluster, VMHost, Build
            $Report.VMHost = $VMHost.Name
            $Report.Build = $VMHost.Build
            $Report
          }
      }
  } | Export-Csv -Path ESXinventory.csv -NoTypeInformation -UseCulture


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
dcoz
Hot Shot
Hot Shot
Jump to solution

Thats great thanks.

It looks to logical when you see it done, but just could figure how to do it.

Thanks

Dougie

0 Kudos