Uncategorized

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.

Comments

10 comments have been added so far

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

  2. 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]

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

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

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

  6. 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}
    }
    }

Leave a Reply

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