<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	
	>
<channel>
	<title>
	Comments on: PowerCLI &#038; vSphere statistics – Part 2 – Come together	</title>
	<atom:link href="https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Fri, 11 Jun 2021 21:09:14 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.9</generator>
<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>
		By: LucD		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-7566</link>

		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Fri, 11 Jun 2021 21:09:14 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-7566</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-7563&quot;&gt;Roger Haines&lt;/a&gt;.

I would limit it to just 1 call to Get-Stat, and then with Group-Object cmdlet order the results via ESXi node.]]></description>
			<content:encoded><![CDATA[<p>I would limit it to just 1 call to Get-Stat, and then with Group-Object cmdlet order the results via ESXi node.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Roger Haines		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-7563</link>

		<dc:creator><![CDATA[Roger Haines]]></dc:creator>
		<pubDate>Fri, 11 Jun 2021 19:18:53 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-7563</guid>

					<description><![CDATA[Great Article Luc.  How would I go about incorporating an array in order to get this info for all hosts in all clusters for a VDI environment?  I thought something like below....

$esxName = Get-VMHost &#124; Select @{N=&quot;Cluster&quot;;E={Get-Cluster -VMHost $_}} #&quot;my-ESX-hostname&quot;
$esxImpl = Get-VMHost -Name $esxName
$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)
$workingDays = &quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;
$dayStart = New-Object DateTime(1,1,1,7,30,0)     # 07:30 AM
$dayEnd = New-Object DateTime(1,1,1,17,30,0)      # 05:30 PM
 
$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-14) -Finish $todayMidnight.AddDays(-7)
$report = $stats &#124; Where-Object {
	$workingDays -contains $_.Timestamp.DayOfWeek -and
	$_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and
	$_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay
}
 
$report &#124; Export-Csv &quot;C:\temp\BusinessHours-cpu.csv&quot; -NoTypeInformation -UseCulture]]></description>
			<content:encoded><![CDATA[<p>Great Article Luc.  How would I go about incorporating an array in order to get this info for all hosts in all clusters for a VDI environment?  I thought something like below&#8230;.</p>
<p>$esxName = Get-VMHost | Select @{N=&#8221;Cluster&#8221;;E={Get-Cluster -VMHost $_}} #&#8221;my-ESX-hostname&#8221;<br />
$esxImpl = Get-VMHost -Name $esxName<br />
$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)<br />
$workingDays = &#8220;Monday&#8221;,&#8221;Tuesday&#8221;,&#8221;Wednesday&#8221;,&#8221;Thursday&#8221;,&#8221;Friday&#8221;<br />
$dayStart = New-Object DateTime(1,1,1,7,30,0)     # 07:30 AM<br />
$dayEnd = New-Object DateTime(1,1,1,17,30,0)      # 05:30 PM</p>
<p>$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-14) -Finish $todayMidnight.AddDays(-7)<br />
$report = $stats | Where-Object {<br />
	$workingDays -contains $_.Timestamp.DayOfWeek -and<br />
	$_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and<br />
	$_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay<br />
}</p>
<p>$report | Export-Csv &#8220;C:\temp\BusinessHours-cpu.csv&#8221; -NoTypeInformation -UseCulture</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: LucD		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-4350</link>

		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Fri, 08 Sep 2017 08:27:21 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-4350</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-4346&quot;&gt;Hossam&lt;/a&gt;.

Hi Hossam,
Without going into too much details now, you should look at a few things:
	&lt;li&gt;Minimise the number of calls to Get-Stat. Rather call it once for all VMs, and then use Group-Object to split out the results per VM. There are a couple of example in my other Statistics posts.&lt;/li&gt;
	&lt;li&gt;Have a look at the ImportExcel module. It would allow you to split the results, per VM or per metric, over multiple worksheets in one XLSX file.&lt;/li&gt;
	&lt;li&gt;Determine how much detail you want. Do you really need a value every 20 seconds? Or would a longer interval suffice for your purpose?&lt;/li&gt;
	&lt;li&gt;Make a good, and meaningful, selection of the metrics you are collecting. Too many metrics means longer runs and bigger files.&lt;/li&gt;

In summary, plan before you code your script!
Regards,
Luc]]></description>
			<content:encoded><![CDATA[<p>Hi Hossam,<br />
Without going into too much details now, you should look at a few things:</p>
<li>Minimise the number of calls to Get-Stat. Rather call it once for all VMs, and then use Group-Object to split out the results per VM. There are a couple of example in my other Statistics posts.</li>
<li>Have a look at the ImportExcel module. It would allow you to split the results, per VM or per metric, over multiple worksheets in one XLSX file.</li>
<li>Determine how much detail you want. Do you really need a value every 20 seconds? Or would a longer interval suffice for your purpose?</li>
<li>Make a good, and meaningful, selection of the metrics you are collecting. Too many metrics means longer runs and bigger files.</li>
<p>In summary, plan before you code your script!<br />
Regards,<br />
Luc</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Hossam		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-4346</link>

		<dc:creator><![CDATA[Hossam]]></dc:creator>
		<pubDate>Mon, 04 Sep 2017 13:33:53 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-4346</guid>

					<description><![CDATA[Hey Luc!

I&#039;m a newbie in this!, so sorry it it is naive question.

 I want to run similar script gather Get-Stat standard metrics for all VMs in 1 cluster containing almost 300 VMs, and store them in 1 CSV or multiple CSVs one for each metric it 1 will be hard to gather every thing in 1 CSV. 

this should be run once a day gathering metrics for each VM in 5 minutes intervals, 

how to do, what to watch for?]]></description>
			<content:encoded><![CDATA[<p>Hey Luc!</p>
<p>I&#8217;m a newbie in this!, so sorry it it is naive question.</p>
<p> I want to run similar script gather Get-Stat standard metrics for all VMs in 1 cluster containing almost 300 VMs, and store them in 1 CSV or multiple CSVs one for each metric it 1 will be hard to gather every thing in 1 CSV. </p>
<p>this should be run once a day gathering metrics for each VM in 5 minutes intervals, </p>
<p>how to do, what to watch for?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: LucD		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-4196</link>

		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Thu, 29 Dec 2016 08:15:33 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-4196</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-4195&quot;&gt;kam007&lt;/a&gt;.

Hi Kam007,
To send a report as an email, you can use the Send-MailMessage cmdlet.
Something like this
&lt;code&gt;
$esxName = &#039;MyEsx&#039;

$esxImpl = Get-VMHost -Name $esxName
$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)
$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-5) -Finish $todayMidnight.AddDays(-4)
$groups = $stats &#124; Group-Object -Property {$_.Timestamp.Hour, $_.Instance}
$report = $groups &#124; % {
    New-Object PSObject -Property @{
        Description = $_.Group[0].Description
        Entity = $_.Group[0].Entity
        EntityId = $_.Group[0].EntityId
        Instance = $_.Group[0].Instance
        MetricId = $_.Group[0].MetricId
        Timestamp = $_.Group[0].Timestamp.Date.AddHours($_.Group[0].Timestamp.Hour)
        Unit = $_.Group[0].Unit
        Value = [math]::Round(($_.Group &#124; Measure-Object -Property Value -Average).Average, 2)
    }
}

$sMail = @{
    From = &#039;lucd@lucd.info&#039;
    To = &#039;lucd@lucd.info&#039;
    Subject = &#039;Report&#039;
    BodyAsHtml = $true
    Body = $report &#124; ConvertTo-Html &#124; Out-String
    SmtpServer = &#039;mail.lucd.info&#039;
}

Send-MailMessage @sMail
&lt;/code&gt;

On your other question, I&#039;m not sure which special tokens you mean.
But there are several great learning resources for PowerShell and PowerCLI available.

Some examples:
&lt;a href=&quot;https://thecrazyconsultant.com/powershell-study-guide-core-concepts/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PowerShell study guide – core concept&lt;/a&gt;
&lt;a href=&quot;https://thecrazyconsultant.com/powercli-study-guide-core-concepts/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PowerCLI study guide – core concepts&lt;/a&gt;

And doing a search for &#039;powershell training free&#039; will bring up a bunch of other resources.

I hope this helps.
Luc]]></description>
			<content:encoded><![CDATA[<p>Hi Kam007,<br />
To send a report as an email, you can use the Send-MailMessage cmdlet.<br />
Something like this<br />
<code><br />
$esxName = 'MyEsx'</p>
<p>$esxImpl = Get-VMHost -Name $esxName<br />
$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)<br />
$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-5) -Finish $todayMidnight.AddDays(-4)<br />
$groups = $stats | Group-Object -Property {$_.Timestamp.Hour, $_.Instance}<br />
$report = $groups | % {<br />
    New-Object PSObject -Property @{<br />
        Description = $_.Group[0].Description<br />
        Entity = $_.Group[0].Entity<br />
        EntityId = $_.Group[0].EntityId<br />
        Instance = $_.Group[0].Instance<br />
        MetricId = $_.Group[0].MetricId<br />
        Timestamp = $_.Group[0].Timestamp.Date.AddHours($_.Group[0].Timestamp.Hour)<br />
        Unit = $_.Group[0].Unit<br />
        Value = [math]::Round(($_.Group | Measure-Object -Property Value -Average).Average, 2)<br />
    }<br />
}</p>
<p>$sMail = @{<br />
    From = 'lucd@lucd.info'<br />
    To = 'lucd@lucd.info'<br />
    Subject = 'Report'<br />
    BodyAsHtml = $true<br />
    Body = $report | ConvertTo-Html | Out-String<br />
    SmtpServer = 'mail.lucd.info'<br />
}</p>
<p>Send-MailMessage @sMail<br />
</code></p>
<p>On your other question, I&#8217;m not sure which special tokens you mean.<br />
But there are several great learning resources for PowerShell and PowerCLI available.</p>
<p>Some examples:<br />
<a href="https://thecrazyconsultant.com/powershell-study-guide-core-concepts/" target="_blank" rel="nofollow">PowerShell study guide – core concept</a><br />
<a href="https://thecrazyconsultant.com/powercli-study-guide-core-concepts/" target="_blank" rel="nofollow">PowerCLI study guide – core concepts</a></p>
<p>And doing a search for &#8216;powershell training free&#8217; will bring up a bunch of other resources.</p>
<p>I hope this helps.<br />
Luc</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: kam007		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-4195</link>

		<dc:creator><![CDATA[kam007]]></dc:creator>
		<pubDate>Thu, 29 Dec 2016 03:44:10 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-4195</guid>

					<description><![CDATA[Hi Lucd,
Your report is excellent and it is running successfully in our environment.
I am learning PowerCli from your book.
Currently I have a requirement that I want to fetch this report in HTML format and receive it in my email directly. 
If it is possible please let me know.
------------------------------------------------------------------------------------
When I am learning your book I found different type of special character and toke have been used in it. As I don&#039;t know any programming language it is difficult to understand. So is it possible to know which programming language training will help me to understand the powercli scripting.]]></description>
			<content:encoded><![CDATA[<p>Hi Lucd,<br />
Your report is excellent and it is running successfully in our environment.<br />
I am learning PowerCli from your book.<br />
Currently I have a requirement that I want to fetch this report in HTML format and receive it in my email directly.<br />
If it is possible please let me know.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
When I am learning your book I found different type of special character and toke have been used in it. As I don&#8217;t know any programming language it is difficult to understand. So is it possible to know which programming language training will help me to understand the powercli scripting.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: LucD		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-2963</link>

		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Fri, 24 Jan 2014 07:24:43 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-2963</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-2961&quot;&gt;MCheung&lt;/a&gt;.

See my reply in &lt;a href=&quot;https://communities.vmware.com/message/2337970#2337970&quot; rel=&quot;nofollow&quot;&gt;sampling interval of get-stat  is changed after the VM is powered off/on&lt;/a&gt;]]></description>
			<content:encoded><![CDATA[<p>See my reply in <a href="https://communities.vmware.com/message/2337970#2337970" rel="nofollow">sampling interval of get-stat  is changed after the VM is powered off/on</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: MCheung		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-2961</link>

		<dc:creator><![CDATA[MCheung]]></dc:creator>
		<pubDate>Fri, 24 Jan 2014 02:06:43 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-2961</guid>

					<description><![CDATA[Dear LucD,

My user is using the below Get-Stat commands on vCenter 5.1 to collect the performance data for the VM ‘VM0000’ daily.

Get-Stat -entity VM001A -stat cpu.usage.average  -Start  -finish 
Get-Stat -entity VM001A -stat mem.usage.average  -Start  -finish 
Get-Stat -entity VM001A -stat disk.usage.average -Start  -finish 

The above commands are executed every day, at 0:20 am, to collect the data for the previous day. The sampling interval is 5 minutes until the VM was powered off for about 20 hours for system maintenance.

After the VM was powered on again, the sampling interval was changed from 5 minutes to 30 minutes on the day the VM was powered on.However, the next day after the VM was powered on, the sampling interval was back to 5 minutes again.
 
Any ideas or explanation on this behavior?  Thanks.]]></description>
			<content:encoded><![CDATA[<p>Dear LucD,</p>
<p>My user is using the below Get-Stat commands on vCenter 5.1 to collect the performance data for the VM ‘VM0000’ daily.</p>
<p>Get-Stat -entity VM001A -stat cpu.usage.average  -Start  -finish<br />
Get-Stat -entity VM001A -stat mem.usage.average  -Start  -finish<br />
Get-Stat -entity VM001A -stat disk.usage.average -Start  -finish </p>
<p>The above commands are executed every day, at 0:20 am, to collect the data for the previous day. The sampling interval is 5 minutes until the VM was powered off for about 20 hours for system maintenance.</p>
<p>After the VM was powered on again, the sampling interval was changed from 5 minutes to 30 minutes on the day the VM was powered on.However, the next day after the VM was powered on, the sampling interval was back to 5 minutes again.</p>
<p>Any ideas or explanation on this behavior?  Thanks.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Malik		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-1778</link>

		<dc:creator><![CDATA[Malik]]></dc:creator>
		<pubDate>Tue, 04 Sep 2012 15:01:09 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-1778</guid>

					<description><![CDATA[Hi LucD
I am try to workout on a script to find out the average CPU, Memory usage for last month. But just for working hours and week days.

i.e. For each VM I need average CPU, memory usage calculated against working hours (8am to 6pm). Also this should skip weekdays. I understand for 1 month report I can have two hours interval (HI3) which is alright in my case. below is the script I am trying out. but it is not working.

Value	Timestamp	MetricId	              Unit	Entity
22.19      31/08/2012	cpu.usage.average	%	APPS1
8.14	       30/08/2012	cpu.usage.average	%	APPS1
7.49	       29/08/2012	cpu.usage.average	%	APPS1
7.53	       28/08/2012	cpu.usage.average	%	APPS1]]></description>
			<content:encoded><![CDATA[<p>Hi LucD<br />
I am try to workout on a script to find out the average CPU, Memory usage for last month. But just for working hours and week days.</p>
<p>i.e. For each VM I need average CPU, memory usage calculated against working hours (8am to 6pm). Also this should skip weekdays. I understand for 1 month report I can have two hours interval (HI3) which is alright in my case. below is the script I am trying out. but it is not working.</p>
<p>Value	Timestamp	MetricId	              Unit	Entity<br />
22.19      31/08/2012	cpu.usage.average	%	APPS1<br />
8.14	       30/08/2012	cpu.usage.average	%	APPS1<br />
7.49	       29/08/2012	cpu.usage.average	%	APPS1<br />
7.53	       28/08/2012	cpu.usage.average	%	APPS1</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: sam		</title>
		<link>https://www.lucd.info/2010/01/05/powercli-vsphere-statistics-part-2-come-together/#comment-1243</link>

		<dc:creator><![CDATA[sam]]></dc:creator>
		<pubDate>Thu, 13 Oct 2011 07:31:11 +0000</pubDate>
		<guid isPermaLink="false">http://lucd.info/?p=1455#comment-1243</guid>

					<description><![CDATA[&lt;a href=&quot;#comment-1241&quot; rel=&quot;nofollow&quot;&gt;@LucD &lt;/a&gt; 
I also try to get more info  just like &quot;-Stat cpu.usage.average,Mem.Usage.Average,disk.Usage.Average&quot;,but seen doesn&#039;t work?]]></description>
			<content:encoded><![CDATA[<p><a href="#comment-1241" rel="nofollow">@LucD </a><br />
I also try to get more info  just like &#8220;-Stat cpu.usage.average,Mem.Usage.Average,disk.Usage.Average&#8221;,but seen doesn&#8217;t work?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
