VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
1 2 Previous Next 28 Replies Last post: Nov 6, 2009 1:07 AM by FirstByte  

Reporting through Powershell posted: Dec 10, 2008 9:09 PM

Click to view ronmanu07's profile Enthusiast 35 posts since
Nov 6, 2007
Hi All,

I was wondering if anyone had any 'already setup' scripts that can run basic reports on ESX through VI Powershell?


Thanks to all in advance. I'm not much of a scritping person, and if anyone has anything already going that is helpful would be much appreciated.


Cheers.

Re: Reporting through Powershell

1. Dec 11, 2008 12:41 PM in response to: ronmanu07
Click to view buckethead's profile Hot Shot 152 posts since
Nov 5, 2005

There are many examples in the VI Powershell Toolkit forum. Chances are pretty high that whatever you want to do is in there.

also, check out the contest entries from the 2008 Powershell contest.

http://communities.vmware.com/community/developer/windows_toolkit


Re: Reporting through Powershell

2. Dec 11, 2008 12:44 PM in response to: buckethead
Click to view gary1012's profile Expert 431 posts since
Feb 20, 2008

Re: Reporting through Powershell

3. Dec 12, 2008 5:44 AM in response to: gary1012
Click to view Texiwill's profile Guru 10,205 posts since
Jan 13, 2004
Hello,

Moved to the VI Toolkit (for Windows) forum.


Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
Blue Gears and SearchVMware Pro Blogs: http://www.astroarch.com/wiki/index.php/Blog_Roll
Top Virtualization Security Links: http://www.astroarch.com/wiki/index.php/Top_Virtualization_Security_Links

Re: Reporting through Powershell

4. Dec 12, 2008 5:53 AM in response to: Texiwill
Click to view gboskin's profile Hot Shot 206 posts since
Nov 19, 2008

You are just in time I have combined a couple of scripts especailly VMware Health Check script and the Guru assitance of LuCD

The Script attached gives you a report ..doing the following

1) Lists all ESX servers

3)List all clusters and calulates VMware capacity for each cluster

Provided detallied information about datstores , RDM and all sorts..

This is the mother of all reports ...... Many thankd to Ivo Beerens ivo@ivobeerens.nl who wrote VMwareHealth Check script and of course LuCD VI tollkit GURU

Attachments:

Re: Reporting through Powershell

5. Dec 14, 2008 5:32 AM in response to: ronmanu07
Click to view alanrenouf's profile Master 582 posts since
Feb 28, 2006
There is also my script which reports a fair bit of information straight into word including bar graphs and pie charts at the following location:

http://communities.vmware.com/docs/DOC-7070

Re: Reporting through Powershell

6. Dec 19, 2008 2:06 AM in response to: gboskin
Click to view ief's profile Enthusiast 28 posts since
Aug 19, 2005

Hello gboskin, thanks for using the healthscript. The list all cluster with the calculate the capacity and the RDM info is very good addition.

blog www.ivobeerens.nl

Re: Reporting through Powershell

7. Dec 23, 2008 1:07 AM in response to: ief
Click to view gboskin's profile Hot Shot 206 posts since
Nov 19, 2008

Thanks I have added 3 more section and run this every morning .....However this gives me a dialy report..

If i want to get a weekly/monthly report. for the following sections

1) VM information

2) Hosts that average over 75% memory usage.

3) M's that average over 75% memory usage.

I know i need to use a - Start and - Finish command ..but not sure how to add this

Regards

Attachments:

Re: Reporting through Powershell

8. Dec 23, 2008 2:28 AM in response to: gboskin
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
That report looks great.

You could add, like you suggested, the -Start and -Finish parameter to the Get-Stat cmdlet.
A handy method to get statistics for the previous day could look like this
Get-Stat .... -Start  (get-date).Date.adddays(-1) -Finish (get-date).Date.addminutes(-1)

More general you could do it like this
$DaysBack = <n>        # Number of days to go back
$DaysPeriod = <m>      # Number of days in the interval
$StatStart = (Get-Date).Date.adddays(- $DaysBack)
$StatFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)
Get-Stat .... -Start $StatStart -Finish $StatFinish

Re: Reporting through Powershell

9. Jan 8, 2009 7:54 AM in response to: LucD
Click to view gboskin's profile Hot Shot 206 posts since
Nov 19, 2008
Final edited version.. Yes this script really does look good ..once again a big thanks to Ivo Beerens ivo@ivobeerens.nl and LUcD
Attachments:

Re: Reporting through Powershell

10. Jan 14, 2009 9:17 PM in response to: gboskin
Click to view Rashida11's profile Novice 21 posts since
Nov 26, 2008

Wow .. Very good work on this scipt . i really love all the new parameters that have been added.

The VM Calculation for daily and weekly memory and cpu used i see is in %. is is possible to get actual values for this ?? .If it can it will be awesome!!!

Re: Reporting through Powershell

11. Jan 28, 2009 6:45 AM in response to: Rashida11
Click to view SetClear's profile Enthusiast 24 posts since
Aug 24, 2007

All,

Here's are few alterations to the script.

I have added reporting for the ESX Hosts volume usage which will alert if above 75%.

(This to me is rather important as I have had a servers log volume run out of space and it more or less took down the Host and all VMs presently hosted.)

I have also added the html formatting into the powershell/html document so that when its emailed it will retain the formatting.

I have also changed the email so the the body contains the actual report, but left it attached also so that if the email reader is not capable of reading the html body it can be detached and read inside a browser.

To be able to use the additional functionality to get Host system information you will have to install putty/plink and modify the file structure to the plink.exe so that it points to your installed location.

Other than that no additional changes besdes smtp stuff is required.

Attachments:

Re: Reporting through Powershell

12. Jan 28, 2009 10:55 AM in response to: SetClear
Click to view bolsen's profile Hot Shot 132 posts since
Nov 8, 2005

Can you please explain line 105?

What is it doing with "C:\Program Files\Veeam\Veeam Backup and FastSCP\Putty\plink"?

Re: Reporting through Powershell

13. Jan 28, 2009 11:01 AM in response to: bolsen
Click to view SetClear's profile Enthusiast 24 posts since
Aug 24, 2007

Bolsen,

$esx_df = & "C:\Program Files\Veeam\Veeam Backup and FastSCP\Putty\plink" -pw Asd123 root@$_ df -h

This line is running is using the plink command which is calling to putty's api to establish the ssh session without opening the GUI.

Once it established the session to $_ as root (root@$_) passing the password (-pw....).

the (df -h) is the remote command that is run and the return values are captured as ($esx_df).

Re: Reporting through Powershell

14. Jun 23, 2009 1:18 PM in response to: gboskin
Click to view Humpadilly's profile Novice 8 posts since
Nov 6, 2008

Hello Everyone,

This is a great script! I have been playing around with it and have managed to use the following to get the Average Memory usage and CPU usage (1 day & 1 week) for the hosts....

######################################################
#Host CPU & Memory Usage
Write-Host "Gathering Host CPU & Memory Usage Information."
function VM-statavg ($vmImpl, $StatStart, $StatFinish, $statId) {

  • $stats = $vmImpl | get-stat -Stat $statId -intervalmin 120 -Maxsamples 360 `*
  • -Start $StatStart -Finish $StatFinish*
  • $statAvg = "{0,9:#.00}" -f ($stats | Measure-Object value -average).average*
  • $statAvg*
}
# Report for previous day
$DaysBack = 1 # Number of days to go back
$DaysPeriod = 1 # Number of days in the interval
$DayStart = (Get-Date).Date.adddays(- $DaysBack)
$DayFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)
# Report for previous week
$DaysBack = 7 # Number of days to go back
$DaysPeriod = 7 # Number of days in the interval
$WeekStart = (Get-Date).Date.adddays(- $DaysBack)
$WeekFinish = (Get-Date).Date.adddays(- $DaysBack + $DaysPeriod).addminutes(-1)
$report = @()
get-vmhost | Sort Name | % {
  • $vm = Get-View $_.ID*
  • $vms = "" | Select-Object VMName, DayAvgCpuUsage, WeekAvgCpuUsage, DayAvgMemUsage, WeekAvgMemUsage*
  • $vms.VMName = $vm.Name*
  • $vms.DayAvgCpuUsage = VM-statavg $_ $DayStart $DayFinish "cpu.usage.average"*
  • $vms.WeekAvgCpuUsage = VM-statavg $_ $WeekStart $WeekFinish "cpu.usage.average"*
  • $vms.DayAvgMemUsage = VM-statavg $_ $DayStart $DayFinish "mem.usage.average"*
  • $vms.WeekAvgMemUsage = VM-statavg $_ $WeekStart $WeekFinish "mem.usage.average"*
  • $Report += $vms*
}
$Report | ConvertTo-Html -title "Host CPU & Memory Usage Information" -body "<H2>Host CPU & Memory Usage Information.</H2>" -head $a | Out-File -Append $filelocation
Write-Host "Host CPU & Memory Usage Information Complete.

Does anyone know if there is an easy way to put this into the clusters section report?

Also is there a command that lists the datastores per cluster?

Cheers

Humpa

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities