<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Search for Required Hosts in Specific Clusters from vCenters with Total Hosts, Guests, CPU and M in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2929038#M108316</link>
    <description>&lt;P&gt;You could do something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;# Connect to all the vCenters
Connect-VIServer -Server 'vc1', 'vc2', 'vc3' -User 'xxx' -Password 'yyy'

foreach ($vc in $global:defaultVIServers) {
  $ca = Get-CustomAttribute -Name 'Host.License' -Server $vc

  Get-Cluster -Name "vc-mix-*" -Server $vc -PipelineVariable cluster |
  ForEach-Object -Process {
    $esx = Get-VMHost -Location $cluster | Where-Object { (Get-Annotation -Entity $_ -CustomAttribute $ca).Value -eq 'Microsoft' }
    $vm = Get-VM -Location $esx
    $stats = Get-Stat -Entity $vm -Stat 'cpu.usagemhz.average', 'mem.consumed.average' -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue

    New-Object -TypeName PSObject -Property ([ordered]@{
        vCenter = $vc.Name
        Cluster = $cluster.Name
        VMHost = $esx.Name -join '|'
        VMHostTotalCpuMhz = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
        VMHostTotalCpuMhzUsed = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum
        VMHostTotalMemGb = ($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum
        VMHostTotalMemGbUsed = ($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum
        VMCount = $vm.Count
        VMTotalCpuMhzUsed = ($stats | Where-Object { $_.MetricId -eq 'cpu.usagemhz.average' } | Measure-Object -Property Value -Sum).Sum
        VMTotalMemMbUsed = [math]::Round(( $stats | Where-Object { $_.MetricId -eq 'mem.consumed.average' } | Measure-Object -Property Value -Sum).Sum / 1KB, 1)
      })
  }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 15 Sep 2022 08:14:03 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2022-09-15T08:14:03Z</dc:date>
    <item>
      <title>Search for Required Hosts in Specific Clusters from vCenters with Total Hosts, Guests, CPU and MEM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2928992#M108314</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Looking for a solution to report by filtering hosts only with custom attribute of 'Host.License' and value of 'Microsoft' from a number of vcenters that has a specific cluster name like 'vc-mix-*'.&lt;/P&gt;&lt;P&gt;From this group of filtered hosts in that specific cluster, tabulate a summary of the totol number of hosts found with total CPU and MEM they have and used.&lt;/P&gt;&lt;P&gt;Also tabluate a summary of the total number of guests found in these hosts in that specific cluster, as well as the total CPU and MEM these guests are using.&lt;/P&gt;&lt;P&gt;I am new to coding and will appreciate any help please? Please let me know if you need more info. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 23:39:12 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2928992#M108314</guid>
      <dc:creator>DonData</dc:creator>
      <dc:date>2022-09-14T23:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Search for Required Hosts in Specific Clusters from vCenters with Total Hosts, Guests, CPU and M</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2929038#M108316</link>
      <description>&lt;P&gt;You could do something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;# Connect to all the vCenters
Connect-VIServer -Server 'vc1', 'vc2', 'vc3' -User 'xxx' -Password 'yyy'

foreach ($vc in $global:defaultVIServers) {
  $ca = Get-CustomAttribute -Name 'Host.License' -Server $vc

  Get-Cluster -Name "vc-mix-*" -Server $vc -PipelineVariable cluster |
  ForEach-Object -Process {
    $esx = Get-VMHost -Location $cluster | Where-Object { (Get-Annotation -Entity $_ -CustomAttribute $ca).Value -eq 'Microsoft' }
    $vm = Get-VM -Location $esx
    $stats = Get-Stat -Entity $vm -Stat 'cpu.usagemhz.average', 'mem.consumed.average' -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue

    New-Object -TypeName PSObject -Property ([ordered]@{
        vCenter = $vc.Name
        Cluster = $cluster.Name
        VMHost = $esx.Name -join '|'
        VMHostTotalCpuMhz = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
        VMHostTotalCpuMhzUsed = ($esx | Measure-Object -Property CpuUsageMhz -Sum).Sum
        VMHostTotalMemGb = ($esx | Measure-Object -Property MemoryTotalGB -Sum).Sum
        VMHostTotalMemGbUsed = ($esx | Measure-Object -Property MemoryUsageGB -Sum).Sum
        VMCount = $vm.Count
        VMTotalCpuMhzUsed = ($stats | Where-Object { $_.MetricId -eq 'cpu.usagemhz.average' } | Measure-Object -Property Value -Sum).Sum
        VMTotalMemMbUsed = [math]::Round(( $stats | Where-Object { $_.MetricId -eq 'mem.consumed.average' } | Measure-Object -Property Value -Sum).Sum / 1KB, 1)
      })
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 15 Sep 2022 08:14:03 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2929038#M108316</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-09-15T08:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Search for Required Hosts in Specific Clusters from vCenters with Total Hosts, Guests, CPU and M</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2929227#M108326</link>
      <description>&lt;P&gt;Wow, if only I could code half like you LucD!&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@84D0B125ABBDD13E116082CCCBA171CD/emoticons/1f44d.png" alt=":thumbs_up:" title=":thumbs_up:" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 06:36:47 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Search-for-Required-Hosts-in-Specific-Clusters-from-vCenters/m-p/2929227#M108326</guid>
      <dc:creator>DonData</dc:creator>
      <dc:date>2022-09-16T06:36:47Z</dc:date>
    </item>
  </channel>
</rss>

