PowerCLI

 View Only
  • 1.  Get-stat monthly CPU utilization

    Posted Jul 25, 2008 01:26 PM

    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?



  • 2.  RE: Get-stat monthly CPU utilization
    Best Answer

    Posted Jul 25, 2008 01:48 PM

    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
    }
    



  • 3.  RE: Get-stat monthly CPU utilization

    Posted Jul 25, 2008 01:58 PM

    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 }



  • 4.  RE: Get-stat monthly CPU utilization

    Posted Jul 25, 2008 04:02 PM

    Sorry, can't get it to work....the PowerGui debugger reports A parameter cannot be found that matches parameter name ' -start'.



  • 5.  RE: Get-stat monthly CPU utilization

    Posted Jul 25, 2008 06:14 PM

    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.



  • 6.  RE: Get-stat monthly CPU utilization

    Posted Jul 25, 2008 07:44 PM

    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'



  • 7.  RE: Get-stat monthly CPU utilization

    Posted Jul 25, 2008 08:53 PM

    The forum SW seems to act up with some browsers.

    I attached the script to make sure you get the correct version.