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.

14 thoughts on “PowerCLI: How many VMs on your Datastores ?”

  1. Hi,

    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

  2. Al

    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.

    regards
    Ferry Limpens

  3. 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

  4. 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,

  5. 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

  6. Al,

    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.

  7. Al,

    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)

Leave a Reply