Home > Blogs > VMware PowerCLI Blog


How to list datastores and VMs that are on shared storage.

A lot of the magic VMware provides relies on shared storage. If a VM is on local storage, you can’t VMotion it, HA won’t restart it, and a host of other limitations. Do you know which of your VMs, if any, are on local storage? This script can make answering that question pretty easy. First, here’s a function that will locate datastores that use shared storage.

To use, launch PowerCLI, connect to your vCenter server, load the function above and run:

And you’ll wind up with a list of datastores that your hosts can share.

But that’s not what we’re after, we want datastores that can’t be shared. Not too hard,


Once we have $localOnly, we pass that to Get-VM.

This gives us the list of VMs that can’t be shared amongst hosts.

11 thoughts on “How to list datastores and VMs that are on shared storage.

  1. Vishnu Mohan

    VMware.Vim.HostParallelScsiHba can also host shared storage devices. For instance, a Mellanox Infiniband SRP initiator shows up as a Parallel SCSI HBA other potential future HBAs (Software FCoE?) might be implemented similarly.

    Reply
  2. Carter Shanklin

    VIshnu, thanks, didn’t know that — I’ll look at that as soon as I have a chance.

    Reply
  3. Chris

    I mush be missing something here. Everything is fine up until the last step.
    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts> $localOnly | Get-VM
    Get-VM : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
    At line:1 char:19
    + $localOnly | Get-VM <<<< [Error repeated 6 times - same as the number of local datastores we have]

    Reply
  4. Jonathan Medd

    Great script, really useful!
    When I run it in my environment it still returns some local datastores though. It only happens on hosts which are a) not connected to the SAN and b) are running Foundation license, any ideas?
    Currently I can filter them out by naming convention, but would prefer not to need to do that.

    Reply
  5. Jonathan Medd

    Further investigation reveals the results contain local storage on all hosts. Any ideas?
    I’ve taken the code exactly as above……

    Reply
  6. Carter Shanklin

    Chris, are you using PowerCLI 4.0?

    Reply
  7. Carter Shanklin

    Jonathan I’ve added some debugging, could you run the script with debugging and either post what it says or send me the results? Thanks.

    Reply
  8. Chris

    Upgrading to 4.0 made this work. Thanks for the help.

    Reply
  9. Jonathan Medd

    Thanks Carter for the debug enhancements. I’ve run it with the datastores query filtered to only match one of the local datastores that were being returned. The debug results are below:
    DEBUG: GSD: Is it NFS? VMware.Vim.VmfsDatastoreInfo
    DEBUG: GSD: first extent: vmhba1:1:0
    DEBUG: GSD: found /vmfs/devices/disks/vml.02000000006006016082c92200f4f61f58b381de11524149442035 on storageSystem-2371
    DEBUG: GSD: LUN details: Name:, Type:disk, Vendor:DGC , Model:RAID 5
    DEBUG: GSD: HBA type is: VMware.Vim.HostFibreChannelHba
    DEBUG: GSO: LocalStore01 is sharable
    This datastore is on a Dell 2950 with no HBAs inside, only using local datastores on a Perc 6i integrated controller – ESX sees this as MegaRAID SAS 1078 Controller.

    Reply
  10. Chris

    I know this is an old post and I am a new user of Powercli. This may be an easier way to do the Get-ShareableDatastore. Please test and let me know.
    Function Get-ShareableDatastore {
    # Get all datastores.
    $datastores = Get-Datastore
    #Loop through all of the datastores
    foreach ($datastore in $datastores){
    #If it is true it is a shareable datastore
    If ($datastore.extensiondata.summary.MultipleHostAccess -eq $true){
    Write-Output $datastore}
    }
    }

    Reply
  11. BestLottie

    I have noticed you don’t monetize your website, don’t waste your traffic, you can earn extra bucks
    every month. You can use the best adsense alternative
    for any type of website (they approve all websites), for more
    details simply search in gooogle: boorfe’s tips monetize your website

    Reply

Leave a Reply

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

*