Automation

 View Only
  • 1.  Script to show performance

    Posted Nov 30, 2009 02:40 PM

    Is there a powershell script that I can run which show the VM's and their current cpu and memory performance. I have a script which can show the cpus and memory allocated, but i would like to find out if there any object properties I could use to get performance data.



  • 2.  RE: Script to show performance

    Posted Nov 30, 2009 02:47 PM

    You could use the Get-Stat cmdlet and ask for the Realtime statistics.

    Have a look at for example



  • 3.  RE: Script to show performance

    Posted Nov 30, 2009 08:48 PM

    Thanks I can get the script working.

    I have exported to a csv file and now have all the VM's listed with their host, cpu, memory. To make the csv file more presentable I want to list all VM's under their host, such as show all the VMs under their host , such as have their all Vm's in the same host listed together, or maybe have a heading for the host and then list all VM's and their performance. Can the above script be edited to show this, is this possible. Thanks



  • 4.  RE: Script to show performance

    Posted Nov 30, 2009 09:30 PM

    For the outut to a CSV file should each line look like this:

    Host VM CPU Memory

    Or did you have something else in mind ?



  • 5.  RE: Script to show performance

    Posted Dec 01, 2009 09:39 AM

    Yes something like this would be good, where the host is listed first and then all the VM's and its all fields are listed.



  • 6.  RE: Script to show performance

    Posted Dec 01, 2009 11:32 AM

    Try this one

    
    Get-VM  | where {$_.PowerState -eq "PoweredOn"} |
    	Select Host, Name, NumCpu, MemoryMB, 
    		@{N="Cpu.UsageMhz.Average";E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddHours(-72) -IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)}}, 
    		@{N="Mem.Usage.Average";E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-72) -IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)}} | `
    	Export-Csv "C:\VM-stats.csv" -NoTypeInformation -UseCulture
    
    

    Don't forget the back-tick on the 2nd to last line !



  • 7.  RE: Script to show performance

    Posted Dec 01, 2009 12:05 PM

    Thanks for the script.

    If I wanted to display the csv file by displaying all the virtual machines in one host first, then the next host. Would you use the sort-object command



  • 8.  RE: Script to show performance
    Best Answer

    Posted Dec 01, 2009 12:08 PM

    Yes, sort with -Properties Host, Name before creating the CSV file



  • 9.  RE: Script to show performance

    Posted Dec 03, 2009 09:55 PM

    Many thanks for the script Luc !

    Kind Regards,

    AWT