<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>group Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/group/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/group/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 10:59:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>group Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/group/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>DRSRule &#8211; a DRS rules and groups module</title>
		<link>https://www.lucd.info/2015/01/22/drsrule-drs-rules-and-groups-module/</link>
					<comments>https://www.lucd.info/2015/01/22/drsrule-drs-rules-and-groups-module/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Thu, 22 Jan 2015 15:00:14 +0000</pubDate>
				<category><![CDATA[Affinity]]></category>
		<category><![CDATA[Anti-affinity]]></category>
		<category><![CDATA[DRS]]></category>
		<category><![CDATA[Group]]></category>
		<category><![CDATA[Host]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Rule]]></category>
		<category><![CDATA[VM]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[anti-affinity]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[rule]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4852</guid>

					<description><![CDATA[One of the nice vSphere features is the ability to define DRS rules. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One of the nice vSphere features is the ability to define <a href="http://pubs.vmware.com/vsphere-55/topic/com.vmware.vsphere.resmgmt.doc/GUID-FF28F29C-8B67-4EFF-A2EF-63B3537E6934.html" target="_blank" rel="noopener noreferrer">DRS rules</a>.</p>
<p><a href="https://www.lucd.info/2015/01/22/drsrule-drs-rules-and-groups-module/drsrule-intro/" rel="attachment wp-att-4854"><img fetchpriority="high" decoding="async" class="aligncenter wp-image-4854" src="https://lucd.info/wp-content/uploads/2015/01/DRSRule-intro.png" alt="DRSRule-intro" width="490" height="315" srcset="https://www.lucd.info/wp-content/uploads/2015/01/DRSRule-intro.png 659w, https://www.lucd.info/wp-content/uploads/2015/01/DRSRule-intro-300x193.png 300w" sizes="(max-width: 490px) 100vw, 490px" /></a>The feature allows a vSphere administrator to control the placement of virtual machines in a vSphere cluster. There are the <strong>VM to VM</strong> <strong>affinity</strong> and <strong>anti-affinity</strong> rules, and the newer <strong>VM to VMHost</strong> rules. With the VM to VMHost rules, vSphere introduced the concept of <strong>VM</strong> and <strong>VMHost groups</strong>, and the ability to have rules that are a <strong>requirement</strong> (&#8216;shall&#8217;) or a <strong>preference</strong> (&#8216;should&#8217;).</p>
<p>In a recent <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank" rel="noopener noreferrer">VMTN PowerCLI community</a> thread a <a href="https://communities.vmware.com/people/EdZ314" target="_blank" rel="noopener noreferrer">PowerCLI user</a> had a query about <a href="https://communities.vmware.com/message/2271796#2271796" target="_blank" rel="noopener noreferrer">exporting and importing DRS rules and groups</a>. At that point <a href="https://twitter.com/mtboren" target="_blank" rel="noopener noreferrer">Matt Boren</a> and myself developed the idea to provide a PowerShell module. The PowerShell module, which we named <a href="https://github.com/PowerCLIGoodies/DRSRule">DRSRule</a>, provides all the functions we deemed useful for working with DRS rules and groups. And yes, the module includes an <strong>export</strong> and an <strong>import</strong> cmdlet !</p>
<p><span id="more-4852"></span></p>
<p><a href="https://twitter.com/mtboren" target="_blank" rel="noopener noreferrer">Matt Boren</a>, famous for the high quality posts on his <a href="https://www.vnugglets.com/" target="_blank" rel="noopener noreferrer">vNugglets blog</a>, and myself, started working on the module, and after some late evenings and long weekends, we now have a first version we want to make public.</p>
<p>There are already many blogposts on the subject of DRS rules and groups. Including some excellent PowerCLI posts. The first one that springs to mind is <a href="https://twitter.com/avlieshout">Arnim</a>&#8216;s excellent <a href="https://www.van-lieshout.com/2011/06/drs-rules/" target="_blank" rel="noopener noreferrer">Managing VMware DRS rules using PowerCLI</a>.</p>
<p>And don&#8217;t forget to read <a href="https://www.vnugglets.com/2015/01/drsrule-new-powershell-module-for-drs.html">Matt&#8217;s post</a> on the DRSRule module as well.</p>
<p>To get you on your way with the DRSRule module, Matt and myself compiled the following introductory text.</p>
<h2>Why the DRSRule module?</h2>
<p>The core <strong>PowerCLI </strong>from VMware allows for many of the DRS rule operations that one might want to perform.  There have been questions over the years in the <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank" rel="noopener noreferrer">VMware Communities PowerCLI</a> forum about how to export DRS rules and groups, and, on how to then import such items.</p>
<p>While there are several posts on the web about how to get/export such things, importing/recreating DRS rules/groups from such exported data has not received much focus.  This was the spark for this DRSRule module:  to allow for easy export/import of such rules/groups.  As part of making a module to handle these actions, other cmdlets were born, like the <strong>Get-/New-/Remove-/Set-*</strong> cmdlet sets for DRS <strong>VM groups</strong> and <strong>VMHost groups</strong>, along with sets for DRS VM to VM rules and VM to VMHost rules.</p>
<h2>How to use the DRSRule module?</h2>
<p>The DRSRule module comes with an <a href="http://raw.githubusercontent.com/PowerCLIGoodies/DRSRule/master/About_DRSRule.help.txt">about_DRSRule</a>.<br />
Once the module is installed, use that help topic to get a general introduction to the use of the DRSRule module:</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-Help about_DRSRule</pre><p></p>
<h2>How to get the DRSRule module ?</h2>
<p>The source for this PowerShell module is hosted on <a href="https://github.com/">GitHub.com</a>.<br />
The repository is managed by the GitHub organization <a href="https://github.com/PowerCLIGoodies" target="_blank" rel="noopener noreferrer">PowerCLIGoodies</a>, and in there is the <a href="https://github.com/PowerCLIGoodies/DRSRule">DRSRule repository</a> itself.</p>
<p>There are a couple of ways to get the module, and use it in your PowerShell session:</p>
<h3>Automated</h3>
<h4>Via a script</h4>
<p>Use a PowerShell script to perform the download and the extract.<br />
The script is included in the repository as file <a href="https://raw.githubusercontent.com/PowerCLIGoodies/DRSRule/master/DownloadLatest.ps1" target="_blank" rel="noopener noreferrer">DownloadLatest.ps1</a>.</p>
<h4>Via PsGet</h4>
<p>If you have the <a href="https://psget.net/" target="_blank" rel="noopener noreferrer">PsGet</a> module loaded in your PowerShell session, then installing this DRSRule module is as simple as updating PsGet and then installing DRSRule:</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Update-Module -Verbose -Module PsGet
Install-Module DRSRule</pre><p></p>
<h3>Manual</h3>
<p>Grab the <a href="https://github.com/PowerCLIGoodies/DRSRule/archive/Latest.zip" target="_blank" rel="noopener noreferrer">latest version</a> from the GitHub repository.<br />
Extract the content to a suitable folder.</p>
<p>You can go for the Modules folder linked to the Windows account you are using. To find this path, run:</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Join-Path ${env:\userprofile} &quot;Documents\WindowsPowerShell\Modules&quot;)</pre><p></p>
<p>Or you can select any other folder.</p>
<p>Either way you will end up with a folder named <strong>[pathToModule]\DRSRule</strong>, in which the PowerShell files for the <strong>DRSRule module</strong> reside.</p>
<p>Then, load the DRSRule module into your session.</p>
<p>If you selected one of the folders in $env:PSModulePath (your PSModule path), you can do this with</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Import-Module DRSRule</pre><p></p>
<p>If you picked another folder, you should use the full path to the folder that contains the module&#8217;s files, like:</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Import-Module [PathToModule]\DRSRule</pre><p></p>
<p>Please also read the note below about using <strong>Unblock-File</strong>, since this module is not Authenticode signed.</p>
<h2>Note on Unblock-File</h2>
<p>Since there is no <strong>Authenticode</strong> certificate supplied for this module, and, assuming that one&#8217;s PowerShell ExecutionPolicy is at least <strong>RemoteSigned</strong>, below is a quick/easy way to unblock files.  But, this should only be done when you trust the code in the files that you are unblocking &#8212; inspecting the files is for your own good.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-ChildItem [pathToModules]\DRSRule | Unblock-File</pre><p></p>
<p>The DRSRule module was set up as community resource, so we are hoping to see your comments, suggestions and code.</p>
<p>Enjoy !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2015/01/22/drsrule-drs-rules-and-groups-module/feed/</wfw:commentRss>
			<slash:comments>56</slash:comments>
		
		
			</item>
		<item>
		<title>PowerCLI &#038; vSphere statistics – Part 4 – Grouping</title>
		<link>https://www.lucd.info/2010/01/24/powercli-vsphere-statistics-part-4-grouping/</link>
					<comments>https://www.lucd.info/2010/01/24/powercli-vsphere-statistics-part-4-grouping/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sun, 24 Jan 2010 18:12:00 +0000</pubDate>
				<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[group]]></category>
		<guid isPermaLink="false">http://lucd.info/?p=1576</guid>

					<description><![CDATA[In a previous post in this series (see PowerCLI &#38; vSphere statistics – [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In a previous post in this series (see <a href="https://lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/" target="_blank">PowerCLI &amp; vSphere statistics – Part 2 – Come together</a>), I showed the usefulness of the <strong>Group-Object</strong> cmdlet when working with statistical data. The script in that post grouped data samples for each hour together, which made it much easier to calculate the hourly average. With the <strong>Group-Object</strong> cmdlet you avoid numerous nested if- or switch-statements.</p>
<p>And best of all, you don&#8217;t have to code the grouping yourself, it was all done for you by the PowerShell Team.</p>
<p>So make sure this cmdlet belongs to your basic PowerShell repertoire. It will prove invaluable when processing statistical data.</p>
<p>This post will show you several of the different options you have to group statistical data together. And I will illustrate each of these with a sample script.</p>
<p><span id="more-1576"></span></p>
<h3>Grouping using one property</h3>
<p>Let&#8217;s start with something simple.</p>
<p>We want to produce a CSV file with the average CPU usage per core on a specific ESX host over the last full hour.</p>
<p>With the <strong>-Start</strong> and <strong>-Finish</strong> parameters of the <strong>Get-Stat</strong> cmdlet we can limit the returned data to the last full hour.</p>
<p>And we know that the <strong>Instance</strong> property has the core-Id or an empty string, to indicate the aggregate value (i.e. the average over all cores).</p>
<p>It is then the obvious choice to <strong>group</strong> the data on the <strong>Instance</strong> property.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$esxName = &amp;quot;esx41.test.local&amp;quot;
$esxImpl = Get-VMHost -Name $esxName
$prevHour = (Get-Date -Minute 0 -Second 0).AddSeconds(-20)
$report = @()

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $prevHour.AddHours(-1) -Finish $prevHour -IntervalMins 5
$groups = $stats | Group-Object -Property Instance
$groups | where {$_.Name -ne &amp;quot;&amp;quot;} | %{
	$report += New-Object PsObject -Property @{
		CoreId = $_.Name
		Average = [Math]::Round(($_.Group | Measure-Object -Property Value -Average).Average, 1)
	}
}
$report | Export-Csv &amp;quot;C:\Core-Avg-1-host-1-hour.csv&amp;quot; -NoTypeInformation -UseCulture</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 3</strong>: Gives a timestamp with the current hour minus some seconds so as not to get a value for the full hour.</p>
<p><strong>Line 6</strong>: We use the <strong>-IntervalMins 5</strong> parameter to make sure Get-Stat returns values for the <strong>complete hour</strong>. If you leave out this parameter, the Get-Stat cmdlet in some cases returns samples from the <strong>Realtime</strong> interval. But then you risk, depending how many minutes after the full hour you run the script, that you don&#8217;t have samples for the complete hour.</p>
<p><strong>Line 7</strong>: The returned statistical data is grouped on the Instance property, which is the Core-Id.</p>
<p><strong>Line 8</strong>: The Where-Object filters out the data for the aggregate instance (the average over all the cores).</p>
<p><strong>Line 9-12</strong>: This uses a PowerShell v2 feature (<strong>-Properties</strong>) of the <strong>New-Object</strong> cmdlet.</p>
<p>Since a picture says more than a 1K words, a simple diagram.</p>
<p style="padding-left: 30px;"><a href="https://lucd.info/wp-content/uploads/2010/01/group-object-property.png"><img decoding="async" class="alignnone size-full wp-image-1586" title="group-object-property" src="https://lucd.info/wp-content/uploads/2010/01/group-object-property.png" alt="" width="602" height="449" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-object-property.png 753w, https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-300x223.png 300w" sizes="(max-width: 602px) 100vw, 602px" /></a></p>
<ul>
<li>Get-Stat returns a number of samples</li>
<li>The CPU core-Id is stored in the Instance property</li>
<li>The Group-Object cmdlet creates a new array element for each value present in the Instance property seen over all the samples</li>
<li>Such an array element contains:
<ul>
<li>a <strong>Name</strong> property that holds in this sample the core-Id</li>
<li>a <strong>Group</strong> property that holds all the samples for the specific code-Id in the Name property</li>
</ul>
</li>
</ul>
<p>If we have a look with the <strong>Variable Inspector</strong> from <a href="https://www.idera.com/Product-Tour/PowerShell-Plus/" target="_blank">PowerShell Plus</a>, we can see how the <strong>$groups</strong> variable is composed.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-object-property1.png"><img decoding="async" class="alignnone size-full wp-image-1601" title="group-object-property" src="https://lucd.info/wp-content/uploads/2010/01/group-object-property1.png" alt="" width="409" height="263" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-object-property1.png 409w, https://www.lucd.info/wp-content/uploads/2010/01/group-object-property1-300x192.png 300w" sizes="(max-width: 409px) 100vw, 409px" /></a></p>
<p>The Group-Object cmdlet creates a <strong>GroupInfo</strong> object for each &#8220;group&#8221; it detects.</p>
<p>In the <strong>Name</strong> property we get the value that was used for a specific group. For <strong>$groups[0]</strong> this is an empty string, in other words the group for the aggregate value. In <strong>$groups[1]</strong> we can see from the Name property that this group instance was for core-Id 0.</p>
<p>The resulting CSV file looks like this when the script is executed on single quad-core Nehalem processor with hyper-threading enabled.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-object-property-CSV.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1594" title="group-object-property-CSV" src="https://lucd.info/wp-content/uploads/2010/01/group-object-property-CSV.png" alt="" width="165" height="164" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-CSV.png 206w, https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-CSV-150x150.png 150w" sizes="auto, (max-width: 165px) 100vw, 165px" /></a></p>
<h3>Grouping using multiple properties</h3>
<p>The previous script produced a CSV file for a specific host. But what if we want the same type of CSV file for multiple ESX hosts ?</p>
<p>In fact this is quite easy with the Group-Object cmdlet, just add the <strong>Entity</strong> property to the -Properties parameter.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$esxImpl = Get-VMHost
$prevHour = (Get-Date -Minute 0 -Second 0).AddSeconds(-20)
$report = @()

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $prevHour.AddHours(-1) -Finish $prevHour -IntervalMins 5
$groups = $stats | Group-Object -Property Entity,Instance
$groups | where {$_.Values[1] -ne &amp;quot;&amp;quot;} | %{
	$report += New-Object PsObject -Property @{
		Hostname = $_.Values[0]
		CoreId = $_.Values[1]
		Average = [Math]::Round(($_.Group | Measure-Object -Property Value -Average).Average, 1)
	}
}
$report | Export-Csv &amp;quot;C:\Core-Avg-All-hosts-1-hour.csv&amp;quot; -NoTypeInformation -UseCulture</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 6</strong>: The additional property Entity was added to include it in the grouping process.</p>
<p><strong>Line 7</strong>: The values for both grouping conditions (Entity and Instance) are available in the Values property of the GroupInfo object. Note that the Name property in the GroupInfo object now contains the values for both grouping conditions.</p>
<p><strong>Line 9</strong>: The first element in the Values array is the hostname. The order of the elements corresponds with order that was used on the -Property parameter of the Group-Object cmdlet.</p>
<p><strong>Line 10</strong>: The second element is the core-Id.</p>
<p>Another look at your best friend the Variables Inspector makes all this perhaps a bit clearer.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-var-inspector-11.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1604" title="group-var-inspector-1" src="https://lucd.info/wp-content/uploads/2010/01/group-var-inspector-11.png" alt="" width="345" height="290" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-var-inspector-11.png 345w, https://www.lucd.info/wp-content/uploads/2010/01/group-var-inspector-11-300x252.png 300w" sizes="auto, (max-width: 345px) 100vw, 345px" /></a></p>
<p>Notice how the Values property contains an array with values for the conditions for a specific group.</p>
<p>And the resulting CSV file looks like this. This was produced for three ESX hosts each with a quad-core Nehalem processor with hyper-threading enabled.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-object-property-all-hosts-CSV.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1603" title="group-object-property-all-hosts-CSV" src="https://lucd.info/wp-content/uploads/2010/01/group-object-property-all-hosts-CSV.png" alt="" width="225" height="407" /></a></p>
<h3>Grouping with Boolean expressions</h3>
<p>We take our first sample script one step further.</p>
<p>This time we only want to report the intervals where one or more of the CPU cores used more than 15% of their capacity. I know this 15% is not really a realistic report but consider it&#8217;s for demonstration purposes and I didn&#8217;t want to overload my test boxes <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$esxName = &amp;quot;esx41.test.local&amp;quot;
$esxImpl = Get-VMHost -Name $esxName
$prevHour = (Get-Date -Minute 0 -Second 0).AddSeconds(-20)
$report = @()

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $prevHour.AddHours(-1) -Finish $prevHour -IntervalMins 5
$groups = $stats | Group-Object -Property {$_.Instance -ne &amp;quot;&amp;quot; -and $_.Value -gt 15}
$groups[$true].Group | %{
	$report += New-Object PsObject -Property @{
		CoreId = $_.Instance
		Time = $_.Timestamp
		Average = [Math]::Round($_.Value, 1)
	}
}
$report | Export-Csv &amp;quot;C:\Core-15%-1-host-1-hour.csv&amp;quot; -NoTypeInformation -UseCulture</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 7</strong>: The -Property parameter is now a <strong>script block</strong> that can return <strong>$true</strong> or <strong>$false</strong>. The test for the aggregate instance is now included in the Boolean expression.</p>
<p><strong>Line 8</strong>: Another great concept by the PowerShell Team, the array of GroupInfo objects is in fact a <strong>hash table</strong>! Which means you get access to a specific group by using the required condition value as a<strong> key</strong>. Since we want all the conditions met, we use the <strong>$true key</strong>.</p>
<p>The view with the <strong>Variable Inspector</strong>.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-var-inspector-2.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1607" title="group-var-inspector-2" src="https://lucd.info/wp-content/uploads/2010/01/group-var-inspector-2.png" alt="" width="375" height="190" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-var-inspector-2.png 375w, https://www.lucd.info/wp-content/uploads/2010/01/group-var-inspector-2-300x152.png 300w" sizes="auto, (max-width: 375px) 100vw, 375px" /></a></p>
<p>And the resulting CSV file.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-object-property-15-percent-CSV1.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1614" title="group-object-property-15-percent-CSV" src="https://lucd.info/wp-content/uploads/2010/01/group-object-property-15-percent-CSV1.png" alt="" width="256" height="90" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-15-percent-CSV1.png 320w, https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-15-percent-CSV1-300x105.png 300w" sizes="auto, (max-width: 256px) 100vw, 256px" /></a></p>
<h3>Nested groups</h3>
<p>And for the &#8220;Pièce de résistance&#8221; we now do this for multiple ESX hosts and we want to produce separate CSV files for each host.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$esxImpl = Get-VMHost
$prevHour = (Get-Date -Minute 0 -Second 0).AddSeconds(-20)
$report = @()

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $prevHour.AddHours(-1) -Finish $prevHour -IntervalMins 5
$groups1 = $stats | Group-Object -Property {$_.Instance -ne &amp;quot;&amp;quot; -and $_.Value -gt 15}
$groups2 = $groups1[$true].Group | Group-Object -Property Entity
$groups2 | % {
	$_.Group | % {
		$report += New-Object PsObject -Property @{
			CoreId = $_.Instance
			Time = $_.Timestamp
			Average = [Math]::Round($_.Value, 1)
		}
	}
	$fileName = &amp;quot;C:\Core-15-percent-&amp;quot; + $_.Name + &amp;quot;.CSV&amp;quot;
	$report | Export-Csv $fileName -NoTypeInformation -UseCulture
}</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 6</strong>: The method for the first grouping is identical to that of the previous script.</p>
<p><strong>Line 7</strong>: The second grouping is done with all the values where the previous Boolean expression returned $true. On those values we now group per Entity which allows us to create  a separate CSV file for each host.</p>
<p><strong>Line 8</strong>: The script loops through all the groups (e.g. hosts).</p>
<p><strong>Line 9</strong>: The script creates an entry for each statistical value.</p>
<p><strong>Line 16-17</strong>: Finally, a CSV file is created for each host.</p>
<p>In my test environment there were two hosts that had cores where the average CPU usage was higher then 15%.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/01/group-object-property-15-percen-all-hosts-CSV.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1617" title="group-object-property-15-percen-all-hosts-CSV" src="https://lucd.info/wp-content/uploads/2010/01/group-object-property-15-percen-all-hosts-CSV.png" alt="" width="267" height="385" srcset="https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-15-percen-all-hosts-CSV.png 334w, https://www.lucd.info/wp-content/uploads/2010/01/group-object-property-15-percen-all-hosts-CSV-208x300.png 208w" sizes="auto, (max-width: 267px) 100vw, 267px" /></a></p>
<h3>Conclusion</h3>
<p>I hope this post made you see the usefulness of the <strong>Group-Object</strong> cmdlet.</p>
<p>Feel free to post any questions or remarks in the Comments section.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2010/01/24/powercli-vsphere-statistics-part-4-grouping/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
	</channel>
</rss>
