I am trying to get a report of how much CPU + Memory has been utilized by VMs in the last month. Being a PS newbie I have tried (for days) pasting several pieces of code I found in this forum together, no luck, the ugliness of my scripts is haunting me......just can't get the GET-stat cmdlet right. Could I get some help?
It would help if you said what statistic values you like to see and in which format (on screen, TXT file, CSV file...)
In any case this a straightforward example that give the average CPU and Memory use for each VM over a 30 day period.
The output is not very pretty or usable, it's just to show you what is possible.
get-vm | %{ Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat cpu.usage.average | select Entity, Timestamp, MetricId, Value, Unit Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It would help if you said what statistic values you like to see and in which format (on screen, TXT file, CSV file...)
In any case this a straightforward example that give the average CPU and Memory use for each VM over a 30 day period.
The output is not very pretty or usable, it's just to show you what is possible.
get-vm | %{ Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat cpu.usage.average | select Entity, Timestamp, MetricId, Value, Unit Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc, thanks for the quick reply. I was adding Export-Csv to output to csv format. The metric I was mostly intersted in was cpu.usagemhz.average and mem.usage.average
So it would look like this:
Get-VIServer -Server <server> -User <user> -Password <pw> get-vm | %{ Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat cpu.usage.average | select Entity,
Timestamp, MetricId, Value, Unit Get-Stat -Entity ($vm) ` -start (get-date).AddDays(-30) ` -stat
mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit }
Sorry, can't get it to work....the PowerGui debugger reports A parameter cannot be found that matches parameter name ' -start'.
Hi, you need to type the script in the next line after using the symbol ` This symbol determines the continuation of the script in next line. If you type the script in the same line you need to remove the symbol '
This might be the issue. Hope this helps.
Thanks for the reply. So, I am struggling a bit. THis is what my (not really ) script looks like at the moment:
get-viserver -server <server> -credentials (get-credential) get-vm | %{ Get-Stat -Entity ($vm) `
-start (get-date).AddDays(-30) -stat cpu.usage.average | select Entity, Timestamp, MetricId, Value, Unit Get-Stat `
-Entity ($vm) -start (get-date).AddDays(-30) -stat mem.usage.average | select Entity, Timestamp, MetricId, Value, Unit}
Debugger spits out: A parameter cannot be found that matches parameter name 'Get-Stat'
The forum SW seems to act up with some browsers.
I attached the script to make sure you get the correct version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference