PowerCLI: How many VMs on your Datastores ?

How many VMs do you have on your datastores ?  Do you know ? should you care ?

Yes, you should care, you should care because over saturated datastores can cause issues with IO and also cause scsi locks if you are using fibre.  So what is the sweet spot ?

Unfortunately its one of those “It Depends” situations, isn’t everything !

It depends on the type of shared storage you are using, fibre, iSCSI, NFS and also depends on the types of VMs you are using, all I can recommend is that you try and distribute your VMs evenly and try and think about the type of VMs you are putting on the same datastore, for example, if you have multiple SQL servers on the same datastore or if you have an exchange server on the same datastore as your SQL VM’s then do something out it.

The first place I would start is by reading the great Yellow-Bricks article “Max amount of VMs per VMFS volume” where Duncan tells us how he works out his sweet spot 😉

You can see how evenly you are currently distributed with the following one-liner:

Get-Datastore | Select Name, @{N="NumVM";E={@($_ | Get-VM).Count}} | Sort Name

Example Output:

Name NumVM
ESX01_Local 0
iscsi_0 0
iscsi_1 2
iscsi_2 1
NFS_1 7

And don’t forget, with the wonders of Move-VM and SVMotion we can move some VM’s around to start evenly distributing the load on our datastores.

I would also suggest monitoring from the SAN up so you can see straight way if you have a volume or LUN issue.

15 thoughts on “PowerCLI: How many VMs on your Datastores ?

  1. maybeageek

    I know, this article is old. But anyway: Does it still work? When I use it with PowerCLi 6.5 and vCenter 6.5, the number of VMs is off.

    For example, one datastore it says 9, but when I look at it, there are at least 14 VMs on that store.
    We have another store where we just put ISOs for installing hosts. No VMs here. It says 35 VMs. But besides 17 ISO files, the store is empty. Where does the 35 come from?

    This makes me doubt all the other outputs of this one-liner as well.

    Any ideas?

  2. Pingback: Count Running Virtual Machines on Datastores – Phasmid LLC

  3. Anoop


    I have a many VMs in my data store that are not added to Vcentre inventory. Is it possible to delete only those VMs through a script as the number is too big to delete manually. The complete setup is in a cluster.

    Thanks in advance

  4. Ferry


    nice oneliner
    but it would be better not only to know who many vm’s are running on the datastore …but also know the amount of used hosts or this ammount of vm for each datastore.

    Ferry Limpens

  5. Anky

    Thanks Guys , its a good one-liner script.

    However I am calling this script in my other script to get the output in HTML format , however the issue is while using this
    $TotalVM = Get-Datastore Sharepoint_Datastore2 | Select Name ,@{N=”TotalVM”;E={@($_ | Get-VM).Count}}| select totalvm

    this gives me output as @{TotalVM=1}

    Also I am using below however I am not getting any output if VM count is less than 2

    $TotalVM = (Get-VM -DataStore $datastore).count

    Since I am new to Powercli , Can someone help me out on this..

    Thanks in Advance

  6. Kris

    Hi Folks,
    I would like to have a script for complete datastore information such as datastore total size & free size, how many # of VMs per datasore currently running that can be run as schedule task and send an email upcon completion the script with the report.

    awaiting your positive response.

    Thank you all in advance,

  7. Virtu-Al

    Thats strange, the only thing I can think of is that it is an issue with copying the code from my site, are you using the “copy Source” button that appears when you hover over the code ?

    Yes, it definately does work on SAN datastores

  8. DCJim


    I admit I am new to PowerCLI scripting (very new, even), but after running this against my cluster, I see a list of the DataStores, but no heading for “NumVM” and no vm count.

    Is it possible I cannot type this one line correctly? Or perhaps this does not work on SAN DataStores?

    Thanks very much for the assistance.

  9. Pingback: FAQ » PowerCLI: How many VMs on your Datastores ?

  10. John


    This is great! I agree with Chris, this would be a perfect addition to the Daily Report (especially if it was set to report based on a custom threshold)

  11. Chris

    Hi Al,
    is this going to make it into V3 of the daily report script ? ( nice to catch up at UKLVMUG yesterday ! )

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.