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
Marcus316
Enthusiast
Enthusiast

Hi LucD,

The only metrics used to calculate the numbers in the tables are the cpu.usage.average and memory.usage.average (Line 14 and 123 of the script).

The goal was to keep it simple in this respect.

Thanks

0 Kudos
TSands82
Contributor
Contributor

Thanks! This is very much appreciated and looks like you put a lot of work into it.

0 Kudos
vmk2014
Expert
Expert

Hi Marc,

      I cant download it from the url.Its blocked here in our company.

Thanks

vmkguy2014

0 Kudos
LittleNickey
Enthusiast
Enthusiast

Nice script!

Does the script save the report locally only temporarily or is it kept after mail has been sent?

Can I define where to save the report and charts? The only user defined variables I see are VC, SMTP Server and To Address.

I get this error for the charts, eventhough I put the script in D:\scripts\

Exception calling "SaveImage" with "2" argument(s): "Access to the path 'D:\vCe

nter_CPU_Usage.png' is denied."

At D:\Script\CapacityReport.ps1:648 char:18

+     $Chart.SaveImage <<<< ($FullPath,"png")

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

    + FullyQualifiedErrorId : DotNetMethodException

-- Oskar
0 Kudos
vmk2014
Expert
Expert

Hi LucD,

      Can you help me in resolving the error.

PowerCLI C:\VMware-KT\Script> .\capacity-management.ps1

Loading...

Preprocessing...

Connect-VIServer : 7/18/2014 3:52:16 PM    Connect-VIServer        Could not re

solve the requested VC server.

At C:\VMware-KT\Script\capacity-management.ps1:56 char:17

+ Connect-VIServer <<<<  $vCenterServerName

    + CategoryInfo          : ObjectNotFound: (:) [Connect-VIServer], ViServer

   ConnectionException

    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_NameR

   esolutionFailure,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVISer

  ver

thanks

vmk2014

0 Kudos
LucD
Leadership
Leadership

At the beginning of the script there is a line

$vCenterServerName = "vCENTER_SERVER_NAME_OR_IP"

Did you substitute that for your vCenter hostname or IP address ?


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

0 Kudos
vmk2014
Expert
Expert

Thanks LucD,

  I missedout to subsitute. After correction i am getting message

Loading...

Preprocessing...

Working with multiple default servers?

    Select [Y] if you want to work with more than one default servers. In this

case, every time when you connect to a different server using Connect-VIServer,

the new server connection is stored in an array variable together with the

previously connected servers. When you run a cmdlet and the target servers

cannot be determined from the specified parameters, the cmdlet runs against all

servers stored in the array variable.

    Select [N] if you want to work with a single default server. In this case,

when you run a cmdlet and the target servers cannot be determined from the

specified parameters, the cmdlet runs against the last connected server.

    WARNING: WORKING WITH MULTIPLE DEFAULT SERVERS WILL BE ENABLED BY DEFAULT

IN A FUTURE RELEASE. You can explicitly set your own preference at any time by

using the DefaultServerMode parameter of Set-PowerCLIConfiguration.

Will it make any changes if select option "Y" becz i have 5 vcenter server in current Environment.

thanks

vmk2014

0 Kudos
LucD
Leadership
Leadership

It seems you have already a vCenter connection open when you run the script.

The prompt comes from the Connect-VIServer cmdlet in the script.

The script will run, but all the information will come from all the connected vCenters, since the script doesn't seem to use the Server parameter on all the Get- cmdlets.

I think it would be better to close all vCenter connections when you run the script


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

0 Kudos
b_johnston
Contributor
Contributor

If you are working with multiple vcenter servers then just add the $DefaultVIServers variable after the $VcenterServername <server name> like this:

$vCenterServerName = "VcenterServer"

$DefaultVIServers="VcenterServer"

LOAGANATHAN
Enthusiast
Enthusiast


Hi Marcus

Great work ...Just checked it works for me nicely

can you please help me to get the report with below requiremnts

1.cpu and memory usage of esx host and VM with particular time period and week day for examples during buisness hours 6.00 Am to 6.00 PM from Mon to fri
2.in virtual machine report is it possible to have how many powered off vms and templates .and how much resources has been configured on powered on vm(no.of Vcpus and RAM) as on consolidated one and folder wise Vm cpu and memory usage during buisness hours 6.00 Am to 6.00 PM from Mon to fri

gravey80
Contributor
Contributor

Great script, but the datastore totals don't seem correct?  Here is what I got;

13 Datastores with a total of 1055 GB of disk space

Datastore Usage Statistics
Datastore NameTotal Disk Space (in GB)Current Usage %Number of VMs containedCommitment %
datastore1274 GB1%00%
datastore1 (1)62 GB2%02%
datastore1 (2)62 GB2%02%
datastore1 (3)62 GB2%02%
Local Storage (Do Not Use)62 GB2%02%
S1-XXXXX700 GB96%23146%
S1-XXXXX360 GB88%18159%
S1-XXXXX300 GB84%184%
S1-XXXXX1100 GB87%27111%
S1-XXXXX420 GB76%295%
S1-XXXXX1000 GB95%7102%
S1-XXXX1000 GB92%19118%
S1-XXXX100 GB84%183%

Clearly I have more than 1055GB Allocated.

The other thing I'd like to know is if there is a way to exclude certain data stores from the script?

I'd like to remove all local host storage, so only my SAN shows in the report.

0 Kudos
gravey80
Contributor
Contributor

Figured out the answers to my own questions...and learnt a bit of CLI along the way Smiley Happy

So the figure quoted in the above table is FREE Disk Space!  I'm going to mod the script to include capacity and free space and perhaps even provisioned.

In order to only report on Storage that VM's were using (SAN Storage and not Local) I changed the following line from;

$Datastores = Get-Datastore | Sort-Object -Property Name #| Select-Object -First 1

to

$Datastores = Get-Datastore -VM $VM | Sort-Object -Property Name #| Select-Object -First 1

0 Kudos
kramerica_666
Contributor
Contributor

Hi Marc & all,

I have downloaded & tried running this script, but not having much luck. I will preface this with the fact that I am no programmer, just looking for something to give me some meaningful capacity information.

When I run the script I get the following in the attachment.

I am sure there's just a " in the wrong place, but any help would be appreciated.

0 Kudos
snteran
Contributor
Contributor

What an amazing report, it has so much information.  Needless to say the script worked flawlessly.  Congrats on your level of expertise, that must be awesome to create such a useful report.

Do you have any ideas of holding an online review of all components for those who are still learning?  Sign me up!

Simply amazing....Cheers.

0 Kudos
vmk2014
Expert
Expert

Hi,

Is it possible to generate report/output in C drive temp folder rather than sending the report in email.I have mentioned in the script the smtp server and recipient email address  but still output i cant see. thanks

Thanks

vm2014

0 Kudos
knightt
Contributor
Contributor

I'm extremely interested in your most recent version of this script.  Can you forward this as I've found no links accessible.  Thanks!

0 Kudos
AdrianoGarcia
Contributor
Contributor

Hello Marcus, thanks for sharing this amazing script.

I like to know if it is possible to change the background color of some specific cells according to criteria, Ex: Memory above 80% the background color red.

If so, could guide me how to do?

Thanks.

0 Kudos
Marcus316
Enthusiast
Enthusiast

Hi Adriano,

Sorry for the delay in response!

It would not be easy to do that in the script's current form, since it has all the numbers in the script as "Integers".

You could do a check to know if a certain Integer is under a defined threshold(in a certain part of the script, the function), however, the problem is you would have to find a way to add the HTML tags to highlight that number (which is in another part of the script).

Take this function for example :

Function GetVMHostAverageMemoryUsagePercentage ($vmhosttemp) { #For the last 30 days

    $AverageMemoryUsagePercentage = Get-Stat -Entity ($vmhosttemp)-start (get-date).AddDays(-30) -Finish (Get-Date)-MaxSamples 31 -stat mem.usage.average

    $AverageMemoryUsagePercentage = $AverageMemoryUsagePercentage | Measure-Object -Property value -Average

    $AverageMemoryUsagePercentage = $AverageMemoryUsagePercentage.Average   

    $AverageMemoryUsagePercentage = [system.math]::ceiling($AverageMemoryUsagePercentage) # Round up

    return $AverageMemoryUsagePercentage

}

Since this function returns an Integer, and the script later EXPECTS an integer, that would mean you have to do a lot of work to adapt the script to use Strings instead of Integers and then add the highlighting condition.

I've considered adding this feature in the past to my script, however it just seemd like too much work compared to the potential benefit...

0 Kudos
jitla1971
Enthusiast
Enthusiast

can you change the email address the script uses to send emails?

Great script and full of great information, thank you very very much.:smileylaugh:

0 Kudos
Marcus316
Enthusiast
Enthusiast

Hi Jitla,

Of course: You can simply modify the variable $ToAddress. (Should be about at line 37 of the script).

Marcus

0 Kudos