VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts)
6 Replies Last post: Jan 4, 2009 2:48 AM by doomdevice  

How to find Local Datastores with Powershell? posted: Oct 5, 2008 1:53 PM

Click to view SCampbell's profile Enthusiast 106 posts since
Apr 18, 2005
You can easily create a local datastore with the New-Datastore -Local option.

I am now trying find local datastores.

So far I am at this to return an array of extents for my VMFS partitions
$DS=Get-DataStore | Where-Object { $Extents=($_ | Get-View).Info.VMFS.Extents; ...


I was going to try to map this to list of LUNs and look at the associated driver. All our shared LUNs will have QLogic or iSCSI S/W drivers
$LUNs= (Get-VMHost | Get-View).Config.StorageDevice.SCSILun 


Has anyone found the easy way to Get-Datastore -Local?

Thanks....

Re: How to find Local Datastores with Powershell?

1. Oct 5, 2008 8:05 PM in response to: SCampbell
Click to view c_shanklin's profile Master 754 posts since
Dec 3, 2007
You might be able to look at the paths associated with the datastores to check their SAN identifiers, which would indicate network storage. I'm not sure that local datastores even have paths.

Re: How to find Local Datastores with Powershell?

2. Oct 7, 2008 11:48 AM in response to: c_shanklin
Click to view DougBaer's profile Expert 602 posts since
Oct 20, 2004
I guess you could walk through your VMhosts and build a list of datastores visible to each host, then weed out the multiple-access ones.

The remaining ones would be local or presented to a single host. Or, you could rely on naming conventions to tell you what is local and what is not.

If you're up for digging into the API a little, there is a boolean called "multipleHostAccess" under the "summary" of the Datastore object.

Re: How to find Local Datastores with Powershell?

4. Oct 8, 2008 7:41 AM in response to: SCampbell
Click to view gstaykov's profile Novice 1 posts since
Jul 3, 2008

You can try using Get-VMHostStorage view


 
$hsv = Get-VMHostStorage -VMHost (Get-VMHost) | Get-View
 
 

I believe that you can found all needed information in $hsv.StorageDeviceInfo.ScsiTopology.Adapter

Look for FibreChannelHba, ParallelScsiHba, BlockHba etc.


Re: How to find Local Datastores with Powershell?

6. Jan 4, 2009 2:48 AM in response to: SCampbell
Click to view doomdevice's profile Enthusiast 98 posts since
Dec 4, 2005
SCampbell, First of all thanks for the script, it was a great help.
But I found an issue within the local datastore function if there are multiple local devices, because comparing the content of an array with the
content of another array with -contains isn´t working in that way.

Furthermore if there are dozens or hundreds of datastores and hosts, I think it´s a good idea to filter datastores first occuring on more than one host.

Therefore I created the following function:

function IsLocalStorage($ds)
{
$hstorage = Get-VMHost -Datastore $ds
$result = $false
	if (!$hstorage.length)
	{
	$LocalDevices=(Get-VMHostStorage -VMHost $hstorage | Get-View).StorageDeviceInfo.HostBusAdapter | `
      Where-Object { `
        ($_.Key -like "key-vim.host.ParallelSCSIHBA-*") -or `
        ($_.Key -like "key-vim.host.BlockHBA-*") `
        } | %{ [string]($_.Device) }
		
		foreach ($ld in $LocalDevices)
		{
		
		$localstorage = $ds | Where-Object { 
			(($_ | Get-View).Info.vmfs.extent | %{ ([string]$_.DiskName).split(":",2)[0]} ) `
			-contains $ld
			}
		}
	 if ($localstorage) {$result = $true}
	}
	
	return $result
}



Call that function with the datastore object, true means it is local storage, false it isn´t.

Comments and improvements are very welcome

Dennis

VI PowerScripter http://www.powerscripter.net
Every Click can be a customized function within VI client

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities