Thin Provisioning and Storage Capacity on vSphere

24 09 2010

I like thin provisioning on vSphere.  I also like not over-allocating datastores by half a terabyte without knowing it.  To prevent crazy amounts of over-allocation (but still keep the environment going with a slightly-less-crazy amount of over-allocation) it is important for me to know the “true” free space on all of my datastores.  By this, I do not mean what vCenter tells me is the free space, but rather a blend of a couple things: the actual usage on the datastore, and the current allocation on that datastore.  With these, I can determine how far I can push the provisioning of virtual machines before I need to worry about running out of space and DOSing other VMs on the same datastore.

Lucky for me, this data is readily available with the PowerCLI, here’s the source code:


.\StorageCapacity.ps1 -server <string> -dbserver <string> -db <string> -overallocate <int>

Where -overallocate is the percentage by which you want to overallocate storage (if at all) & the account you run the script as must have at least Read-Only access to vCenter Server and data reader role on the virtualcenter SQL db.

This script is a work-in-progress, but has come in very handy when I am placing VMs, and their virtual disks, in our environment.  Also, I reuse parts of this script in a series of scripts that auto-provision VMs for our group and external customers via a custom web request form.  (more on the auto-provisioning stuff another time…)

Right now, the script scours the virtual environment for VMs & templates, then tracks how much space their virtual disks and swap files take up.  After adding that all up, it displays (and outputs a CSV of) all of the useful information per datastore, including the “real” free space available, capacity that includes your over-allocation %, provisioned space, and normal free space.  In a future (more accurate) version, I plan to also include log files, since those can actually take up significant space.




46 responses

31 03 2011
Scott Walkingshaw


Did you complete writing this powershell script? I’ve tried it but it fails with the following error:

You cannot call a method on a null-valued expression.
At C:\scripts\StorageCapacity.ps1:75 char:39
+ $vmDisks = $DataSet.Tables[0].Select <<<< ("Name LIKE '$vmName'")
+ CategoryInfo : InvalidOperation: (Select:String) [], RuntimeExc
+ FullyQualifiedErrorId : InvokeMethodOnNull

I'm no expert on powershell scripts but think it's because $DataSet has not been populated.

Can you help please, would love to get it working.


31 03 2011

Hi Scott,

Yes, I actually use this script regularly in our environment. Can you include the values (masked for anything you don’t want to paste here) that you used for each parameter when calling the script?

– Curtis

7 04 2011
Scott Walkingshaw

Hi Curtis

Apologies for the delay in getting back to you. Parameters as follows:

StorageCapacity.ps1 -server vcservername -dbserver vcservername -dbname VirtualCenter -overallocate 150

7 04 2011

Hi Scott,

A couple of questions, just as a sanity check:

– is the database a local installation? (as in SQL is installed on the vCenter Server system)
– does the account you are using to run the script have explicit db reader rights on the SQL db?

If the first question is a “yes”, I will have to bring up a test instance to see if I can replicate the problem, as all of my testing involved a remote SQL instance and I don’t know how SQL Express handles this. I would hope it doesn’t make a difference…

– Curtis

9 04 2011
Scott Walkingshaw

Hi Curtis

The answer is yes to both questions.



12 04 2011
Scott Walkingshaw

Hi Curtis

I’m not sure this is an issue with the SQL and vCenter being on the same server. The script does output the vmfs volume name, available and free space, see below. That proves it can connect to the DB.

Name : volume1
Capacity : 439.725
Provisioned : 0
Available : 439.725
Free Space : 399.203125

12 04 2011

Hi Scott,

Can you paste the following snippet from the script into an open PS window (after defining $dbserver and $db):


$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = “Server = $dbserver; Database = $db; Integrated Security = True”
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet

If there are any errors, please paste them here, if not, please paste the results of entering the following at the PS prompt:


18 04 2011

Hi Scott,

Figured this one out after looking carefully back through this thread. In my post (and in the script) my example uses a parameter $dbname, which is not the actual parameter name for identifying your database. It is actually $db, so:

StorageCapacity.ps1 -server vcservername -dbserver vcservername -db VirtualCenter -overallocate 150

should get you what you need. I’ll also update the post and sample in the .ps1 to reflect this error. Sorry for the confusion,

– Curtis

11 08 2011
Don (@dnwhittaker)

My Virtual Center server is running 4.1 Update 1 and my SQL server is running SQL server 2008. Has your script been tested in that environment?

13 08 2011

Hi Don,

Yes, that’s the environment in which I did the most testing actually. 🙂


26 09 2011
Storage Capacity Script (PowerShell) – new and improved! « Notes from a Sysadmin

[…] LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); LD_AddCustomAttr("theme_bg", "ffffff"); LD_AddCustomAttr("theme_border", "cccccc"); LD_AddCustomAttr("theme_text", "000000"); LD_AddCustomAttr("theme_link", "515151"); LD_AddCustomAttr("theme_url", "f78b0c"); LD_AddCustomAttr("LangId", "1"); LD_AddCustomAttr("Autotag", "technology"); LD_AddSlot("wpcom_below_post"); LD_GetBids(); Like this:LikeBe the first to like this post. […]

9 02 2012

Hi, I tried this script, I am getting error post executing last command $SqlAdapter.Fill($DataSet)

PS C:\Scripts> $SqlAdapter.Fill($DataSet)
Exception calling “Fill” with “1” argument(s): “Incorrect syntax near ‘`’.”
At line:1 char:17
+ $SqlAdapter.Fill <<<< ($DataSet)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

20 12 2012

Mark’s Square on foot from the center of town and the many birds that occupy the area to feed. Despite breathtaking mountain scenery and a rich diversity of hill tribe cultures, Vietnam. I consider the evidence for remote viewing to be pretty clear-cut.

22 02 2013

Have you ever considered about adding a little bit
more than just your articles? I mean, what you say is valuable
and everything. Nevertheless just imagine if you added some
great visuals or videos to give your posts more, “pop”!
Your content is excellent but with images and video clips,
this website could definitely be one of the very best in its niche.

Awesome blog!

30 03 2013

It’s an remarkable post in favor of all the web visitors; they will take benefit from it I am sure.

23 04 2013
learn more

Two thumbs way up for marvelous material. I must say that I am shocked your page is so far down
in the listings. I believe it was on page 5…. and pages 1
through 4 had little useful info which I could possibly use.
Man, the big g has really gone to the toliet.

11 05 2013

Do you have a spam problem on this blog; I also am a blogger, and I was wondering your situation; we have developed some nice methods and we are looking to exchange methods with other folks, why not shoot me an e-mail
if interested. with twitter Protected and straightforward from The biggest Twitter endorsements supplier.

trustworthy company allow us to buy targeted twitter
followers affordable as well as easy.
buy real twitter followers offers quality sociable services.

10 08 2013
buy facebook fans

Hello! I’m at work surfing around your blog from my new apple iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the fantastic work!

29 10 2013

Every weekend i used to go to see this website,
for the reason that i wish for enjoyment, for the reason that this this web page conations actually pleasant funny data too.

you always can buy facebook fans,, by reputable manufacturers for less and protected
buy likes about facebook Risk-free and from most significant facebook likes company.

how to get likes on facebook delivers level of quality sociable
expert services.
If you want to how to get more likes on facebook for your facebook consideration,
there are various very effective approaches.

3 11 2013
buy cheap instagram followers

Pretty section of content. I just stumbled upon your site and in accession capital to assert
that I acquire in fact enjoyed account your blog posts. Any way I will be
subscribing to your augment and even I achievement you
access consistently rapidly. buy cheap instagram followers will
probably be an exceptionally wise investment decision for your company.

instagram followers in instagram Harmless and straightforward from
The greatest instagram endorsements supplier.
buy instagram followers for cheap about instagram Protected and
Easy in the greatest instagram followers service provider. five thousand Quality
followers For jus $29. nine Spend less.
Get More Traffic by buy instagram followers cheap for your Profile effective way.

12 01 2014
how to get more likes on facebook

What’s up colleagues, pleasant article and good arguments commented here,
I am really enjoying by these. facebook page, how to get more likes on facebook, get more Admirers about
facebook for business, buy facebook fans

5 06 2014

This paragraph will assist the internet visitors
for creating new web site or even a blog from start to
end. A great way to twitter should be to have got stars
attract the write-up for you personally.
twitter for a discount and fast, Come on Admirers for your page.

17 06 2014

I like the helpful info you supply in your articles.
I will bookmark your weblog and test onc more here frequently.

I am quite sure I’ll be told a lot of new stuff proper here!Good luck for the next!

19 06 2014
buy followers instagram free

It’ѕ аwesome foг me to have a website, whiich is useful іn favor of my
experience. thanks admin

26 06 2014
How To Get More Followers On Instagram Fast

Magnificent beat ! I would like to apprentice even as you amend
your website, how can i subscribe for a blog site? The account aided me a acceptable deal.
I have been a little bit acquainted of this your broadcast provided shiny clear idea

26 08 2015


Thin Provisioning and Storage Capacity on vSphere | Notes from a Sysadmin

25 11 2015
alltagsbegleiter gehalt 2015

Selbstverständlich kannst du nun deine Startseite auch mit Widgets versorgen oder aber mit benutzerdefinierten Felder.

23 12 2015

Schneiden Sie die Wurzeln des Rotsalbei (Apotheke)
klein, geben Sie diese in eine durchsichtige Flasche und füllen Sie
mit Rotwein auf.

10 01 2016

Eine ausgewogene Ernährung sollten Sie idealerweise mit reichlich Bewegung kombinieren.

10 02 2016
Gesundheit laut Who

Forschungen haben ergeben, dass vier Stück frische Selleriestäbchen täglich den Arterienhochdruck bis zu 15 % senken.

23 02 2016
Gesundheits Nachrichten

Lebensmittel mit einem hohen Kohlenhydratanteil oder
Stärke sollten gemieden werden.

23 02 2016
Gesundheit im Fernsehen

Viele Frauen fühlen sich in der Schwangerschaft nicht mehr
attraktiv und sind von Unsicherheit geplagt und auch das muss ein Mann auffangen können.

24 02 2016

Eine gesunde Ernährung sollte abwechslungsreich sein, mit viel Obst,
Gemüse und Vollkornprodukten.

24 02 2016

Die richtige Ernährung kann man lernen – wir unterstützen Sie dabei
mit zertifizierten Kursangeboten aus dem Präventionsfeld – Ernährung.

3 03 2016
Ratgeber Medizin

Jedoch hat so ein Buch auch seine Reize… und so muss jeder selbst wissen, wie
und wo er nach diesen Infos sucht.

5 03 2016

Bedenken Sie immer, dass eine gesunde Ernährung niemals zu 100 Prozent basisch ist.

5 03 2016
Stiftung Gesundheit

Wie das Ergebnis der Untersuchung zeigt, ist hoher Blutdruck oftmals die Folge von Übergewicht und keine eigentliche Krankheit.

5 03 2016
Gesundheitszentrum Ernaehrung

Die abgebildeten Artikel können wegen des begrenzten Angebots schon am ersten Tag ausverkauft sein.

5 03 2016
Mein Gesundheit

Wer gesund und schlank bleiben will, der muss seine Ernährung langfristig umstellen.

6 03 2016
Medizin Forum Gesundheit Wissen Arzt

Die Therapie umfasst meist mehrere Bausteine wie
Abbau von Übergewicht, regelmäßige Bewegung
und – falls notwendig – blutdrucksenkende Medikamente.

6 03 2016

Babys möchten sich im Schlaf auch mal abstützen und brauchen daher einen sicheren Halt.

7 03 2016

Im Schlaf nochmal leichter abnehmen ohne Sport könnte man, indem man den Stoffwechsel
z. B. über einen kleinen Abendspaziergang anregt.

9 03 2016
Zentrum der Gesundheit Erfahrung

Wenn Sie Schokolade durch gesunde Zwischenmahlzeiten ersetzen, brauchen Sie
nie mehr ein schlechtes Gewissen zu haben.

13 03 2016
Medizinische Tipps

Ist der Blutdruck allerdings sehr hoch, empfehlen Experten meist eine unmittelbare Behandlung mit Medikamenten.

15 03 2016

Nur wenn Ihr Arzt ernstere Ursachen ausschliessen kann, können Sie sich mit ihm über alternative Mittel absprechen.

26 03 2016

Mit den Selbstbestimmt-Essen-Übungen finden Sie heraus, welche Bedürfnisse Sie sich mit Essen erfüllen, wenn Sie essen, obwohl Sie satt
sind bzw.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: