PowerCLI

 View Only
  • 1.  adding host name to Get-Stat

    Posted Apr 07, 2011 08:11 PM

    I am wanting to get an output of the average cpu usage for all of our servers. I am using the following code however I would like each line to also list the host that it came from. Right now it just outputs the date/time/% I would like to output this to a CSV so I can import in Excel and sort by hostname.

    Any help would be much appreciated as I am pretty new to this and still looking through a lot of web sites and examples. (http://www.lucd.info/2009/12/30/powercli-vsphere-statistics-part-1-the-basics/)

    $vhosts - (get-vmhost)

    foreach ($vhost in $vhosts){

    Get-Stat -Entity (Get-VMHost $vhost) -Stat cpu.usage.average

    }

    Thanks in advance.



  • 2.  RE: adding host name to Get-Stat

    Posted Apr 07, 2011 08:50 PM

    To get the host name also and write the output to a .csv file you can do:

    Get-VMHost | Get-Stat -Stat cpu.usage.average | `
    Select-Object -Property @{N="VMHost";E={$_.Entity}},TimeStamp,Value,Unit,Instance,Description | `
    Export-CSV -Path stats.csv -NoTypeInformation -UseCulture


    Regards, Robert