5 Replies Latest reply on May 17, 2018 9:43 PM by LucD

    Powercli help

    mekhan Lurker

      Hi I have following powercli script to gather vcenter info. I need to add to get a list of hostnames, cluster name, folder name and VM name in it. Can someone help:

      $hostinfo = @()
              ForEach ($vmhost in (Get-Cluster | Get-VMHost))
              {
                  $HostView = $VMhost | Get-View
                              $HostSummary = "" | Select MemorySizeGB, CPUSockets, CPUCores, Version
                              $HostSummary.MemorySizeGB = $HostView.hardware.memorysize / 1024Mb
                              $HostSummary.CPUSockets = $HostView.hardware.cpuinfo.numCpuPackages
                              $HostSummary.CPUCores = $HostView.hardware.cpuinfo.numCpuCores
                              $HostSummary.Version = $HostView.Config.Product.Build
                              $hostinfo += $HostSummary
                          }

      $vminfo = @()
                  foreach($vm in (Get-Cluster | Get-VM))
              {
                      $VMView = $vm | Get-View
                      $VMSummary = "" | Select VMSockets,VMCores,CPUSockets,CPUCores,VMMem
                      $VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
                      $VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
                      $VMSummary.VMMem = $VMView.Config.Hardware.MemoryMB

                      $vminfo += $VMSummary
                  }

        • 1. Re: Powercli help
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          And how would you combine that in 1 row?

          • 2. Re: Powercli help
            mekhan Lurker

            Thanks LucD to look at it. Script put the values in another variable, like:

             

            $TotalHostRAM = ($hostinfo | Measure-Object -Property "MemorySizeGB" -Sum).Sum / 1024

            $TotalVMRAM = ($vminfo | Measure-Object -Property "VMMem" -Sum).Sum / 1024 / 1024

             

            Not sure if there is any other efficient way to achieve this goal.

            • 3. Re: Powercli help
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              That's not what I mean, how would you combine all that information on 1 row?

              Do you report for each VM, or each VMHost...?

              How would an output row of the script look like?

              • 4. Re: Powercli help
                mekhan Lurker

                Data will feed to BI software. so separate list of hosts and separate list of virtual machines and other stuff will be good enough. At this moment I am not sure how BI software will massage the data but I think that should work.

                 

                Thanks

                • 5. Re: Powercli help
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  Have a look at this.

                  There is some redundancy in there, but it should capture the information you're after.

                   

                  $report = foreach($vc in $global:defaultVIServers){

                     foreach($cluster in Get-Cluster){

                     foreach($vmhost in Get-VMHost -Location $cluster){

                     foreach($vm in Get-VM -Location $vmhost){

                     $obj = [ordered]@{

                    vCenter = $vc.Name

                    Cluster = $cluster.Name

                    VMHost = $vmhost.Name

                    Folder = $vm.Folder.Name

                    VM = $vm.Name

                    EsxMemorySizeGB = $vmhost.ExtensionData.hardware.memorysize / 1024Mb

                    EsxCPUSockets = $vmhost.ExtensionData.hardware.cpuinfo.numCpuPackages

                    EsxCPUCores = $vmhost.ExtensionData.hardware.cpuinfo.numCpuCores

                    EsxVersion = $vmhost.ExtensionData.Config.Product.Build

                    VMSockets = $vm.ExtensionData.Config.Hardware.NumCpu

                    VMCores = $vm.ExtensionData.Config.Hardware.NumCoresPerSocket

                    VMMem = $vm.ExtensionData.Config.Hardware.MemoryMB

                    }

                     New-Object PSObject -Property $obj

                    }

                    }

                    }

                  }


                  $report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture