Hello
I am new to vSphere PowerCLI (just over a month of dabbling), and I'm building up a script that we can use to perform various operations.
My current hurdle is how to find out what LUN a datastore is on. The vSphere Client shows this data with apparent ease.
I can obviously get info for a datastore:
$objDataStore = get-datastore -name "PLOEVA01_VMFS_001"
$objDataStore | Format-List
FreeSpaceMB : 467655
CapacityMB : 511744
Accessible : True
Type : VMFS
Id : Datastore-datastore-113
Name : PLOEVA01_VMFS_001
...and I can then get a .NET view, and delve a bit deeper:
$objDataStoreView = Get-View -id $objDataStore.id
$objDataStoreView
Info : VMware.Vim.VmfsDatastoreInfo
Summary : VMware.Vim.DatastoreSummary
Host : {VMware.Vim.ManagedObjectReference, VMware.Vim.ManagedObjectReference}
Vm : {VMware.Vim.ManagedObjectReference, VMware.Vim.ManagedObjectReference, VMware.Vim.ManagedObjectRe
ference, VMware.Vim.ManagedObjectReference}
Browser : VMware.Vim.ManagedObjectReference
Capability : VMware.Vim.DatastoreCapability
Parent : VMware.Vim.ManagedObjectReference
CustomValue : {}
OverallStatus : green
ConfigStatus : gray
ConfigIssue : {}
EffectiveRole : {-1, 5}
Permission : {}
Name : PLOEVA01_VMFS_001
DisabledMethod : {}
RecentTask : {}
DeclaredAlarmState : {alarm-9.datastore-113}
TriggeredAlarmState : {}
AlarmActionsEnabled : True
Tag : {}
Value : {}
AvailableField : {}
MoRef : VMware.Vim.ManagedObjectReference
Client : VMware.Vim.VimClient
...the Info and Summary properties give some additional info:
$objDataStoreView.info
Vmfs : VMware.Vim.HostVmfsVolume
Name : PLOEVA01_VMFS_001
Url : sanfs://vmfs_uuid:4a6daf9a-fde9d1f2-ee8b-001b784495e2/
FreeSpace : 490371809280
MaxFileSize : 274877906944
Timestamp : 03/11/2009 14:18:46
DynamicType :
DynamicProperty :
$objDataStoreView.summary
Datastore : VMware.Vim.ManagedObjectReference
Name : PLOEVA01_VMFS_001
Url : sanfs://vmfs_uuid:4a6daf9a-fde9d1f2-ee8b-001b784495e2/
Capacity : 536602476544
FreeSpace : 490371809280
Uncommitted : 8694775296
Accessible : True
MultipleHostAccess : True
Type : VMFS
DynamicType :
DynamicProperty :
...but I just cannot find a correlation between this and a LUN. In desperation, I knocked up a routine (below) which enumerates the fibre HBAs in a given host, enumerates the visible LUNs, then the paths, picks the active paths and reports any paths that lead to a fibre disk. The last step would be to list the datastores on this disk. But how?
Any thoughts... anyone?
Thank you
Simon Catlin
-
MY FUNCTION FOR ENUMERATING A HOST'S STORAGE:
<See EXAMPLE_CODE.TXT attachment>
EXAMPLE OUTPUT:
<See EXAMPLE_OUTPUT.txt attachment>
Can't seem to stop this editor mangling my code example. If you'd like a copy of the code to see what I'm trying to do, let me know.
Thanks
Not sure if this is what you're asking for, but here's my guess.
$t = get-vmhost -datastore datastorename | Select-Object -Last 1 -Property Name
get-scsilun -vmhost $t.name | format-table -autosize
CanonicalName ConsoleDeviceName LunType CapacityMB MultipathP
olicy
-
-
-
-
-
vmhba1:0:13 /vmfs/devices/disks/vml.02000d00006006016041561a00b82d742836f0dc11524149442035 disk 1099247 MostRec...
vmhba1:0:4 /vmfs/devices/disks/vml.02000400006006016041561a00fc1f387733f0dc11524149442035 disk 1099247 MostRec...
vmhba1:0:8 /vmfs/devices/disks/vml.02000800006006016041561a007c1b9e9533f0dc11524149442035 disk 1099247 MostRec...
vmhba1:0:11 /vmfs/devices/disks/vml.02000b00006006016041561a00f2da0ef537f0dc11524149442035 disk 824435 MostRec...
Thanks for that.
It's almost what I need.
This gives me hosts attached to a datastore, and then the SCSI LUNs for
each host. The missing bit for me is tying the LUNs with the original
datastore.
Essentially, I'm trying to understand which datastores are on a LUN, so
that we can perform SAN operations (snapshots, mirroring, etc), and
understand which datastores we are affecting.
I appreciate that a LUN can contain more than one datastore, and a
datastore can have extents on multiple LUNs.
I'm now exploring the depths of paths and extents...
Regards
Simon
I now have this working. Essentially I needed to examine the paths for each HBA, and then look for datastore extents.
I'll now close this one off.
Catman, would you post the solution please? Thanks.
Bizarre,
when I try your script, it does nothing.
is there a switch I'm missing?
.\script.ps1 /HOST:server.domain.local
thanks
Try calling the script like this
.\script.ps1 server.domain.local
or
.\script.ps1 -VIHost server.domain.local
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Guys-- I'm looking for something limilar but cant get it down.
I'd like to get a list of datastore names, their size, & the CanonicalName of ALL datastores in a given Datacenter and output that to a csv.
Is this possible?
Thanks!
@ OsburnM:
This may be close to what you are looking for (borrowed heavily from Luc's examples 🙂 ) :
this is great for sorting out but;
can i get only the lun which has "vmhba1:0:4" for example? i want to find a particular lun with the runtimename's lun ID section, which is the lun ID given by the storage mapping.
Cheers,
Luc has a great function here, and does a much better job of explaining the nuances:
http://www.lucd.info/2010/10/17/runtime-name-via-extensiondata-and-new-viproperty/
HTH!
j