houghtp
Contributor
Contributor

Datastore Name and Mulitpath Info

hi

how can i get datastore name and multipath info into a nice report. so for example

datastore name | multipath policy | preferred path

datastore1 fixed 0:0:22

i can get each individual property but can't seem to combine them in this way.

thanks

22 Replies
240Zeus
Enthusiast
Enthusiast

There's no really simple way to do this from what I can see. If you're using extents you could have multiple extents in a single datastore which all could have different pathing policies as well as preferred paths which is something to think about as well....

Anyway, you're going to have to compare the DiskName from HostVmfsVolume.Extent to the LunID in ConfigManager.StorageSystem.StorageDeviceInfo.MultipathInfo.lun to get these three on a single line of output. Here is the snippet I use to grab my pathing policy and preferred path on each LUN. I'll leave it up to you to insert your datastore name or I'll post something as a followup if I have time to come back to this later. You'll have to forgive my lack of proper "OO-ness" as I come from a bash scripting background:

$esxhost = "enter FQDN of ESX host"

$h = Get-VMHost $esxhost

$hostView = Get-View $h.Id

$storageSystem = Get-View $hostView.ConfigManager.StorageSystem

foreach ($lun in $storageSystem.StorageDeviceInfo.MultipathInfo.lun)

{Write-Host $lun.Policy.Policy, $lun.Policy.Prefer}

Z

0 Kudos
admin
Immortal
Immortal

Some of the stuff in this post may help. In 1.5, which is in Beta right now actually we've introduced cmdlets to make this a lot easier.

0 Kudos
houghtp
Contributor
Contributor

hi 240Zeus , i had something pretty similar to that, but as you can see yourself its hard to tie in the datastore name to the output!

Carter, is that beta public?

0 Kudos
LucD
Leadership
Leadership

Based on I think the following script does what you want.

$esxhost = <ESX-name>

$hss = Get-View (Get-View (Get-VMHost -Name $esxhost).ID).ConfigManager.StorageSystem
foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
  if($mount.Volume.Type -eq "VMFS"){
    foreach($ext in $mount.Volume.Extent){
      foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){
	    if($lun.Id -eq $ext.DiskName) {break}
	  }
	  Write-Host $mount.Volume.Name $lun.Policy.Policy $ext.DiskName
    }
  }
}

Note1: you can easily drop the test for VMFS datastores if required.

Note2: the script can be expanded to report on the actual path used (vis-a-vis the preferred path if the policy is fixed).

For that you can loop through the $lun.Path array and test which path is "active".


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
houghtp
Contributor
Contributor

Hi Luc

thats works! i've extended the script as per your suggestion although $activepath gives me the same value as $ext.DiskName

$esxhost = #############

$hss = Get-View (Get-View (Get-VMHost -Name $esxhost).ID).ConfigManager.StorageSystem

foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){

if($mount.Volume.Type -eq "VMFS"){

foreach($ext in $mount.Volume.Extent){

foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){

if($lun.Id -eq $ext.DiskName) {

foreach($Path in $lun.path){

if ($Path.pathstate -eq "active"){

$activepath = $path.name

break

}

}

break

}

}

Write-Host $mount.Volume.Name $lun.Policy.Policy $ext.DiskName $activepath

}

}

}

0 Kudos
LucD
Leadership
Leadership

Does the VI Client (Configuration - Storage and then select a DS and select Properties) confirm what the script shows ?

If you set the policy to "fixed" and change the preferred path, this path will be made active immediately (when it is of course available).

Or are you saying that you see 2 active paths ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
240Zeus
Enthusiast
Enthusiast

I got something working last night that I'll post for you after I get in to work and clean it up a little.

0 Kudos
houghtp
Contributor
Contributor

sorry i replied to your post then realised what i was doign wrong (i had = instead of -eq. in if ($Path.pathstate -eq "active")) and went back to edit my post, mustn't have got there in time!

the script i posted does actually work.

$esxhost = "svr-vmh-crcla01.lbcamden.net"

$hss = Get-View (Get-View (Get-VMHost -Name $esxhost).ID).ConfigManager.StorageSystem

foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){

if($mount.Volume.Type -eq "VMFS"){

foreach($ext in $mount.Volume.Extent){

foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){

if($lun.Id -eq $ext.DiskName) {

foreach($Path in $lun.path){

if ($Path.pathstate -eq "active"){

$activepath = $path.name

break

}

}

break

}

}

Write-Host $mount.Volume.Name $lun.Policy.Policy $ext.DiskName $activepath

}

}

}

0 Kudos
240Zeus
Enthusiast
Enthusiast

Very similar to what I came up with - sorry I didn't post for you last night houghtp:

0 Kudos
houghtp
Contributor
Contributor

that's quite alright!

thanks for replying!!

0 Kudos
240Zeus
Enthusiast
Enthusiast

Unlike my script, LucD's you can point to a specific host to get the datastore information which is useful if you are not clustering all of your ESX hosts. I wrote mine to target specifically HA/DRS clusters, enumerate the shared datastores, then grab the first host out of the Datastore.Host array and that's where I'm correlating the Datastore name and Lun ID to perform the pathing logic.

If all you want is to target an ESX host, LucD's script is the way to go.

Z

0 Kudos
admin
Immortal
Immortal

Carter, is that beta public?

It's a private beta, unfortunately, part of the larger VI beta.

0 Kudos
jsenon
Contributor
Contributor

Hi All, Hi LucD,

I run this excellent script in ESX 3.5 environnent and all informations are ok, but when I run this script on ESX 4 environnement we don't see the Active Path Column.

I join my script.

Have you got any idea ?

Thanks.

0 Kudos
LucD
Leadership
Leadership

The original script indeed has a problem in vSphere 4.x.

Try this version. It assumes you use PowerCLI 4.1!

$esxhost = <esxhostname>

$hss = Get-View (Get-VMHost -Name $esxhost).Extensiondata.ConfigManager.StorageSystem

foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
	if($mount.Volume.Type -eq "VMFS"){
		foreach($ext in $mount.Volume.Extent){
			foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){
				if(($hss.StorageDeviceInfo.ScsiLun | where{$_.Key -eq $lun.Lun}).CanonicalName -eq $ext.DiskName) {
					foreach($Path in $lun.path){
						if ($Path.pathstate -eq "active"){
							$activepath = $path.name
							break
						}
					}
					break
				}
			}
			Write-Host $mount.Volume.Name $lun.Policy.Policy $ext.DiskName $activepath
		}
	}
} 

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jsenon
Contributor
Contributor

Thanks Luc, but I have this error :

E:\PowerShell> $hss=get-view (Get-VMHost -Name xxx).Extensiondata.ConfigManager.StorageSystem

Get-View : The argument cannot be null or empty.

At line:1 char:14

+ $hss=get-view <<<< (Get-VMHost -Name xxx).Extensiondata.ConfigManager.StorageSystem

0 Kudos
LucD
Leadership
Leadership

Are you sure you are using PowerCLI 4.1 ?

Do a

Get-PowerCLIVersion

to check.

In any case the below script also works pre-PowerCLI 4.1

$esxhost = <esxhostname>

$hss = Get-View (Get-VMHost -Name $esxhost | Get-View).ConfigManager.StorageSystem

foreach($mount in $hss.FileSystemVolumeInfo.MountInfo){
	if($mount.Volume.Type -eq "VMFS"){
		foreach($ext in $mount.Volume.Extent){
			foreach($lun in $hss.StorageDeviceInfo.MultipathInfo.Lun){
				if(($hss.StorageDeviceInfo.ScsiLun | where{$_.Key -eq $lun.Lun}).CanonicalName -eq $ext.DiskName) {
					foreach($Path in $lun.path){
						if ($Path.pathstate -eq "active"){
							$activepath = $path.name
							break
						}
					}
					break
				}
			}
			Write-Host $mount.Volume.Name $lun.Policy.Policy $ext.DiskName $activepath
		}
	}
} 

It could also be that the host is not returned.

Does

Get-VMHost -Name xxx

return anything ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jsenon
Contributor
Contributor

Thanks Luc

Are you sure you are using PowerCLI 4.1 ?

Do a

> Get-PowerCLIVersion
> 

to check.

Yes :

PS C:\> Get-PowerCLIVersion

PowerCLI Version

-


VMware vSphere PowerCLI 4.0 U1 build 208462

Does

> Get-VMHost -Name xxx
> 

return anything ?

PS C:\> get-VMHost -Name fr0-esx2007-v01

Name State PowerState Id CpuUsage CpuTotal Memory Memory

Mhz Mhz UsageMB TotalMB

-


-


-


-- -


-


-


-


fr0-esx2007-... Connected PoweredOn ...-327 303 7600 926 12223

I don't understand

0 Kudos
LucD
Leadership
Leadership

You are using PowerCLI 4.0 update 1, not PowerCLI 4.1.

You can use the 2nd script which doesn't use the Extensiondata property.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jsenon
Contributor
Contributor

Oups, sorry.

Thanks a lot Luc.

0 Kudos