VMware Cloud Community
Marcus316
Enthusiast
Enthusiast

PowerCLI script for vSphere capacity planning

Hello everyone!

After recent discussion on vSphere Capacity planning, I thought I would share one of the tools I use for this purpose. This is a side project I've been working on for few months.

I present to you, my very own "VMware Capacity & Performance Report PowerCLI script (v2.1 Community edition)"

http://1drv.ms/1J00vkq

(Click here then click on "Download")

This is a complex PowerCLI script I wrote, that generates an e-mail report that gives you insight into the current state of your VMware vSphere environment's capacity. It generates tables, pie charts and line charts with information about CPU, Memory & Storage capacity, VM Provisioning Potential, Cluster Resilience and more. Check the script's #INFORMATION block for more information about prerequisites, script input and output.

Have a look at the report it generates and let me know what you think of it!

Please share your thoughts and comments!

Marc Davoli

http://ca.linkedin.com/in/marcvincentdavoli/

Edited on May 25 : Changed OneDrive link to updated script v2.1 with bugfix (for cluster names with a space in it)

160 Replies
jitla1971
Enthusiast
Enthusiast

Hi Marcus

$ToAddress = "destinationadress1@company.com", "destinationadress2@company.com", "destinationadress3@company.com"

Basically what i am trying to do, is send the email from vcenter-alerts@abc.com to vmteam@abc.com

So do i need to add vcenter-alerts@abc.com to the destination address?

As i just added vmteam@abc.com to the destination address.

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Marcus,

Thank you so much for sharing this wonderful script.

I have one problem when received E-mail from Reporting Server. I can able to see tables with values, but not able to see Bar & Pie Charts in this report.

I can able to understand you have used <img> tag for attaching charts to this report, but for this image should be locally present on the machine where we are looking this report.

For Cross checking I have converted the report into html and viewed in Reporting Server and I can able to see charts along with tables.

Could you please suggest is there any way that we can able to see Charts on Body of E-mail where Charts are not stored locally on that machine.

Thanks in Advance,

Siva

0 Kudos
Marcus316
Enthusiast
Enthusiast

Hello Sivaramsharmar,

This is most likely a permission issue on the folder where the images are written to.

Make sure the account you run the script with has Read & Write permissions on that folder.

0 Kudos
Marcus316
Enthusiast
Enthusiast

Hi Jitla,

It's very simple:

The $FromAddress variable should contain the e-mail address you want to receive the e-mail report from (this can be a fictional address)

The $ToAddress variable should contain the e-mail address(es) that you want to send the report to.

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Marcus,

Folder Contains Full Control for Administrators.

We are running your script on Win2k8 Server and we were able to see tables with charts in HTML page as the bar & pie charts are available locally on win2k8 Server.

We are receiving E-mail(from Win2k8 Server) with tables when we are seeing it on Win7 Machine and not able to see Charts.

Is it mandatory to have Win7 Machine in network when viewing this Report. Instead of Charts it is displaying as X mark as image in the report.

Please suggest.

0 Kudos
khushal
Contributor
Contributor

Hi,

First of all , thanks for this wonderful piece of work.. however I am getting below error, in the middle of script...

           Creating chart...

           Calculating Virtual Machine Average Usage Statistics for Cluster VMC01P

           Gathering Cluster Resilience Information for Cluster VMC01P

Method invocation failed because [System.Object[]] doesn't contain a method named 'op_Subtraction'.

At C:\EIL\CPReport-v2.0-Community-Edition.ps1:496 char:4

+             $ClusterFreeMemory = $ClusterTotalMemory - $ClusterUsedMemory - $ACPolicyInte ...

+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (op_Subtraction:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [System.Object[]] doesn't contain a method named 'op_Subtraction'.

At C:\EIL\CPReport-v2.0-Community-Edition.ps1:499 char:4

+             $ClusterFreeMemoryPercentage = $ClusterFreeMemoryPercentage - $ACPolicyIntege ...

+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (op_Subtraction:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [System.Object[]] doesn't contain a method named 'op_Division'.

At C:\EIL\CPReport-v2.0-Community-Edition.ps1:512 char:4

+             $HAReservedMemory = ($ACPolicyInteger/100) * ($ClusterTemp | Get-VMHost | Mea ...

+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

           Creating chart...

Exception calling "DataBindXY" with "2" argument(s): "Data points insertion error. Number of X values is less than Y values

Parameter name: xValue"

At C:\EIL\CPReport-v2.0-Community-Edition.ps1:608 char:2

+     $Chart.Series["Data"].Points.DataBindXY($NameArray, $ValueArray) #Modified by M ...

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentOutOfRangeException

0 Kudos
LucD
Leadership
Leadership

Could it be that you have 2 clusters that fit that name ?

Does

Get-Cluster -Name VMC01P

return more than 1 object ?


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

0 Kudos
khushal
Contributor
Contributor

I think I found the issue... When I run the script first time in the power shell it works flawless but if I run the script again in the same shell it throws these errors.

0 Kudos
rgarvelink
Enthusiast
Enthusiast

is there anyway to scan just a single cluster within a data center? Id like to speed the results up in my large environment.

0 Kudos
SakiBones
Contributor
Contributor

BonJour Marc,

Great script.

I have one question, how often do you run the script

I also added to the bottom the following two lines.

########################### Remove old files #################################

remove-item ($SCRIPT_PARENT + "*.html") -force

remove-item ($SCRIPT_PARENT + "*.png") -force

Just to do some cleanup.

Regards

Steve

How often do you

0 Kudos
sohailr81
Contributor
Contributor

Hi Guyz,

Need help here.
I am getting below error when I run the script.

Capture.PNG

0 Kudos
LucD
Leadership
Leadership

Did you check if there is a back-tick at the end of the previous line ?


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

0 Kudos
Marcus316
Enthusiast
Enthusiast

Hi SakiBones,

I used to run the script monthly, but recently I set it to run on the 1st and 15th of every month.

I use it mostly to ensure there are no clusters or datastore that are not near full capacity.

Thanks

0 Kudos
Coozybones
Contributor
Contributor

Love the Script!

I need to use different credentials for accessing some of the VC's in my environment. How can i do this within the script?

Many thanks in advance.

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Hi Coozybones,

             You can store your Credential in XML file by executing below command for connecting different VC's with out specifying Credentials in plain text file.

New-VICredentialStoreItem -Host "vCenter1" -User "domain\useracnt" -Password "password"

By default your credentials will be stored in encrypted format in XML file in this location(%APPDATA%\VMware\credstore\vicredentials.xml) after executing above command.

If you have special Characters in Password then use single quote.

Change Below Values in Script and try it once.

$vCenterServerName = "vCenter1","vCenter2"

foreach($vcenter in $vCenterServerName){

connect-viserver -server $vcenter

Script Code..................

..............

disconnect-viserver -server $vcenter

}

Replace $vCenterServerName with $vcenter in Script Code.

0 Kudos
Marcus316
Enthusiast
Enthusiast

Hi Coozybones,

By default, when you run the PowerCLI cmdlet "Connect-VIServer" it tries to use the current user to login.

So I just run Windows scheduled tasks with a service account called something like "svc_CPReport" and give that account read-only access to my vCenter.

That way, you don't have to hardcode a username/password inside the script.

- Marc

0 Kudos
Coozybones
Contributor
Contributor

Perfect!

Many thanks for your help.

0 Kudos
anilandhale
Contributor
Contributor

Hi,

Can some one share the sample output of the script?

Thanks.

0 Kudos
vipal
Contributor
Contributor

When i run this script i am not getting any output except (Datastore, CPU and Memory usage in %).  Any idea what could be issue?  Also, in CPU report in Y-axis i am getting value upto 50 only normally it should be 100.

I have powershell 3.0 and Powercli version 5.1

0 Kudos
mummonth
Enthusiast
Enthusiast

Hey, Marcos!

Absolutely great work you did with the script, it`s awesome.

I just wanted to share with you the bug I found that leads to improper building of HTML file, resulting in troubles showing pictures.

I was able to rack the issue, it raises in "per Cluster" part of report, when you building string <img src= and Cluster names has spaces in it.

For cluster names without spaces it works fine, but for cluster name like this:

ERP HA - EVC Westmere

I get this source code in HTML:

  <img src="Cluster_ERP" ha="" evc="" westmere_datastore_usage.png="" />

And as a result, the image fail.

It happens in "per Cluster" part of report for CPU/RAM/Datastore.

I am not too good with HTML, so I was able to track the issue, but haven't yet found how to resolve it properly.

Something need to be adjusted in this part of code:

# CHART
Create-Chart -ChartType Bar -ChartTitle "Monthly Average Host CPU Usage Percentage" -FileName ("Cluster_" + `
$ClusterTemp.Name + "_CPU_Usage") -ChartWidth 1750 -ChartHeight 650 -NameArray $global:ArrayOfNames -ValueArray $global:ArrayOfValues
$HTMLBody += "<IMG SRC=Cluster_" + $ClusterTemp.Name + "_CPU_Usage.png>"
$Attachments += "Cluster_" + $ClusterTemp.Name + "_CPU_Usage.png"
0 Kudos