ronmanu07
Enthusiast
Enthusiast

Reporting through Powershell

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.

0 Kudos
31 Replies
buckethead
Hot Shot
Hot Shot

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

0 Kudos
gary1012
Expert
Expert

Some basic stuff is in this doc: .

Community Supported, Community Rewarded - Please consider marking questions answered and awarding points to the correct post. It helps us all.
0 Kudos
Texiwill
Leadership
Leadership

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

--
Edward L. Haletky
vExpert XII: 2009-2020,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
0 Kudos
gboskin
Enthusiast
Enthusiast

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

0 Kudos
alanrenouf
VMware Employee
VMware Employee

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

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
ief
Contributor
Contributor

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

blog www.ivobeerens.nl
0 Kudos
gboskin
Enthusiast
Enthusiast

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

0 Kudos
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gboskin
Enthusiast
Enthusiast

Final edited version.. Yes this script really does look good ..once again a big thanks to Ivo Beerens and LUcD

0 Kudos
Rashida11
Contributor
Contributor

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!!!

0 Kudos
SetClear
Enthusiast
Enthusiast

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.

0 Kudos
bolsen
Enthusiast
Enthusiast

Can you please explain line 105?

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

0 Kudos
SetClear
Enthusiast
Enthusiast

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 ( the password (-pw....).

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

0 Kudos
Humpadilly
Contributor
Contributor

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*

}

    1. 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)

    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 "&lt;H2&gt;Host CPU & Memory Usage Information.&lt;/H2&gt;" -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

0 Kudos
flipster
Contributor
Contributor

Hi Humpa,

Nice script. Can you kindly post the actual script file?

Thanks!

0 Kudos
pvjsingh
Contributor
Contributor

Hi,

I am having a problem running this script since upgrading to 3.5U4.

See: http://communities.vmware.com/docs/DOC-10327

Error:

Incomplete string token.

At C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\Healthcheck.ps1:121 char:270

+ $vmhosts | Sort Name -Descending | % { $server = $_ |get-view; $server.Config.Product | select { $server.Name },

Version, Build, FullName }| ConvertTo-Html â?"body "&lt;H2&gt;$cluster Cluster Information.&lt;/H2&gt;" -head "&lt;link rel='styleshee

t' href='style.css' type='text/css' / &lt;&lt;&lt;&lt; &gt;" | Out-File -Append $filelocation

Any ideas?

Jason

http://www.ttgapers.com
0 Kudos
LucD
Leadership
Leadership

Is the text â?" between the Convert-To-Html and the -body parameter ?

Or did happen due to the copy and paste to this thread ?

I just ran the script HealthcheckEDITED[1].ps1 on a VC 2.5u4 without a problem.

Which script did you use ? There are several attached to that thread.

From where do you run the script ?

PowerCLI prompt, Windows scheduled task, EcoShell, PowerGui, PowerShell Plus,... ?

And with which version of PowerCLI ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pvjsingh
Contributor
Contributor

Hi,

I am running the script from Powershell prompt as I usually do.

Thanks.

http://www.ttgapers.com
0 Kudos
pvjsingh
Contributor
Contributor

Oh, the funny "a" is really a "-", believe a copy and paste issue.

Jason

http://www.ttgapers.com
0 Kudos