VMware

Trying to dig into PowerCLI but don’t know PowerShell? Start here. | Main | VMworld 2009: PowerCLI and PowerShell roundup.

August 13, 2009

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:

Get-ShareableDatastore

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,

$sharableIds = Get-ShareableDatastore | Foreach { $_.ID } 
$localOnly = Get-Datastore | Where { $sharableIds -notcontains $_.ID }

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

$localOnly | Get-VM

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

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c328153ef0120a549d27d970c

Listed below are links to weblogs that reference How to list datastores and VMs that are on shared storage.:

Comments

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.

Carter Shanklin

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

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]

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.

Jonathan Medd

Further investigation reveals the results contain local storage on all hosts. Any ideas?

I've taken the code exactly as above......

Carter Shanklin

Chris, are you using PowerCLI 4.0?

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.

Chris

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

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.

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

Post a comment

If you have a TypeKey or TypePad account, please Sign In.

About this Blog

This blog provides insight and highlights for VMware PowerCLI, the best tool for automating management and configuration of VMware vSphere.

Subscribe via RSS  

Recommended Reading

Pimp your PowerCLI

Twitter


Facebook

    VMware Blogs