VMware Cloud Community
mprobst2011
Contributor
Contributor
Jump to solution

set preferred path on a lun by naa ID or by lun number

I am looking for a script to set the preferred path for a lun or 2 at a time. I would like to do it by naa id or lun #.  some of the luns are rdm if it matters.

I have been searching and only seen scripts that set all luns to a hba for preferred path.   esxi 4.1 hosts if it matters

mike

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That is strange, the Get-ScsiLun cmdlet takes a HBA object from the pipeline.

You can get help for all the Select-Object parameters with

Get-Help Select-Object -Parameter *

To get the 2nd object, you could do

Select-Object -Index 1

Btw are you on PowerCLI 5.0.1 now ?


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

View solution in original post

Reply
0 Kudos
15 Replies
CRad14
Hot Shot
Hot Shot
Jump to solution

I haven't used it myself yet, but this is directly from the set-scsilunpath  help

C:\PS>$scsilun = Get-ScsiLun -VMHost 10.23.123.100 -LunType disk
$scsipath = Get-ScsiLunPath -ScsiLun $scsilun
Set-ScsiLunPath -ScsiLunPath $sp -Preferred $true
Sets the specified SCSI Lun path as preferred.

Hope that helps!

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
Reply
0 Kudos
mprobst2011
Contributor
Contributor
Jump to solution

I went back and reread the info on the set-scsilunpath commandlet, it leaves me confused.   which of those variables would be the naa. ID? and I assume $sp is the vmhba I want to be preferred?

If I run the first command against my host, I get this

[vSphere PowerCLI] C:\> Get-ScsiLun -VMHost my.exs.host -LunType disk
CanonicalN ConsoleDeviceName              LunType    CapacityMB MultipathPolicy
ame
---------- -----------------              -------    ---------- ---------------
naa.600... /vmfs/devices/disks/naa.600... disk           139488 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk           512078 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk          1048593 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk           512141 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk          2096128 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk          1048593 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk          1048593 Fixed
naa.60a... /vmfs/devices/disks/naa.60a... disk           512078 Fixed
Reply
0 Kudos
CRad14
Hot Shot
Hot Shot
Jump to solution

That's funny, I didn't notice that at first.

I think there is an error in the Help for that cmdlet...

I believe the $sp should actually be the $scsipath variable which was defined in the previous line.

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
Reply
0 Kudos
mprobst2011
Contributor
Contributor
Jump to solution

that makes more sense, but I dont understand why all the luns gathered in the first line would not be passed to the variable in the second line as an array? I only want to update a few luns, some of my hosts can see over 200

It seems from reading the help that this command would do what I want if I knew what to use to specify the lun

$scsipath = Get-ScsiLunPath -ScsiLun <LUNIdentifier>

Set-ScsiLunPath -ScsiLunPath $scsipath -Preferred $true

I have been playing around with putting diffferent things in place of <LUNIdentifier>, but not finding anything that returns valid information, and when it does, I am expecting it to return all paths to the LUN, so how would the second line know which one I need to set as preferred. I am guessing that if I could find a value that worked on the first line, I could use get-scsilunpath to list the paths, and then input that specific path into the set-scsilunpath commandlet

Reply
0 Kudos
CRad14
Hot Shot
Hot Shot
Jump to solution

One way to get a specific lun/datastore would be

Get-datastore Volume3 | Get-scsilun | Get-scsilunpath

Gotta love the Pipe! #TWSS

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
mprobst2011
Contributor
Contributor
Jump to solution

it does not seem that the get-scsilun can use the output of get-datastore?

[vSphere PowerCLI] C:\> get-vmhost myhostname | get-datastore COMMON_MAS001_ISO001_S
Name                               FreeSpaceMB      CapacityMB
----                               -----------      ----------
COMMON_MAS001_ISO001_S                  505140          512000
[vSphere PowerCLI] C:\> get-vmhost  myhostname  | get-datastore COMMON_MAS001_ISO001_S | get-scsilun
Get-ScsiLun : 3/28/2012 2:48:17 PM    Get-ScsiLun        Could not find ScsiLunInterop with CanonicalName 'naa.60a98000486e2
f36584a5a4251596472'.
At line:1 char:105
+ get-vmhost  myhostname  | get-datastore COMMON_MAS001_ISO001_S | get-scsilun <<<<
    + CategoryInfo          : ObjectNotFound: (naa.60a98000486e2f36584a5a4251596472:String) [Get-ScsiLun], VimException
    + FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Command
   s.Host.GetScsiLun
Get-ScsiLun : 3/28/2012 2:48:20 PM    Get-ScsiLun        Could not find ScsiLunInterop with CanonicalName 'naa.60a98000486e2
f36584a5a4251596472'.
At line:1 char:105
+ get-vmhost  myhostname  | get-datastore COMMON_MAS001_ISO001_S | get-scsilun <<<<
    + CategoryInfo          : ObjectNotFound: (naa.60a98000486e2f36584a5a4251596472:String) [Get-ScsiLun], VimException
    + FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Command
   s.Host.GetScsiLun
Get-ScsiLun : 3/28/2012 2:48:39 PM    Get-ScsiLun        Could not find ScsiLunInterop with CanonicalName 'naa.60a98000486e2
f36584a5a4251596472'.
At line:1 char:105
+ get-vmhost  myhostname  | get-datastore COMMON_MAS001_ISO001_S | get-scsilun <<<<
    + CategoryInfo          : ObjectNotFound: (naa.60a98000486e2f36584a5a4251596472:String) [Get-ScsiLun], VimException
    + FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Command
   s.Host.GetScsiLun
Get-ScsiLun : 3/28/2012 2:48:42 PM    Get-ScsiLun        Could not find ScsiLunInterop with CanonicalName 'naa.60a98000486e2
f36584a5a4251596472'.
At line:1 char:105
+ get-vmhost  myhostname  | get-datastore COMMON_MAS001_ISO001_S | get-scsilun <<<<
    + CategoryInfo          : ObjectNotFound: (naa.60a98000486e2f36584a5a4251596472:String) [Get-ScsiLun], VimException
    + FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Command
   s.Host.GetScsiLun
[vSphere PowerCLI] C:\Scripts\mikep\VMware\preferred paths>
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI version are you running ?

With PowerCLI 5.0.1 this works


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

Reply
0 Kudos
mprobst2011
Contributor
Contributor
Jump to solution

I am still running 4.1 u1, let me upgrade, I am getting closer though

[vSphere PowerCLI] C:\Scripts\mikep\VMware\preferred paths> get-vmhost myhostname | get-scsilun
-canonicalname "naa.60a98000486e2f36584a5a4251596472" | get-scsilunpath | select *
Name              : fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.60a98000486e2f36584a5a4251
                    596472
ScsiLunId         : HostSystem-host-39852/naa.60a98000486e2f36584a5a4251596472
ScsiLun           : naa.60a98000486e2f36584a5a4251596472
LunPath           : fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.60a98000486e2f36584a5a4251
                    596472
SanId             : 50:0A:09:82:87:39:79:2F
State             : Standby
Preferred         : False
ScsiCanonicalName : naa.60a98000486e2f36584a5a4251596472
Uid               : /VIServer=userxyz@myhostname:443/VMHost=HostSystem-host-39852/ScsiLun=naa.60a98000486e2f36584
                    a5a4251596472/ScsiLunPath=fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.
                    60a98000486e2f36584a5a4251596472/
ExtensionData     : VMware.Vim.HostMultipathInfoPath

...  I cut out info, but 4 paths returned here ......

[vSphere PowerCLI] C:\> set-scsilunpath -scsilunpath "fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.60a98000486e2f36584a5a4251" -preferred $true

Set-ScsiLunPath : Cannot bind parameter 'ScsiLunPath'. Cannot convert the "fc.20000000c97f2805:10000000c97f2805-fc.500a09808

739792f:500a09828739792f-naa.60a98000486e2f36584a5a4251" value of type "System.String" to type "VMware.VimAutomation.ViCore.

Types.V1.Host.Storage.Scsi.ScsiLunPath".

At line:1 char:29

+ set-scsilunpath -scsilunpath <<<<  "fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.60a98000

486e2f36584a5a4251" -preferred $true

    + CategoryInfo          : InvalidArgument: (:) [Set-ScsiLunPath], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetScsiLunPa

   th

I will upgrade to 5 and see what happens. I am guessing that the name is what I need to be passing?
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's perhaps easier to use the Get-ScsiLun with the CanonicalName parameter and then pipe the resulting object to the Set-ScsiLun cmdlet.


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

mprobst2011
Contributor
Contributor
Jump to solution

wont that pass all 4 paths to the set-scsilun? how would it know which one to mark as preferred?or is there a way to specify what HBA when I pass it?

Reply
0 Kudos
mprobst2011
Contributor
Contributor
Jump to solution

I cannot pass the results from get-scsilun with a pipe to set-scsilunpath, and I tried passing it to just set-scsilun, but did not know what to specify for a path then.

PowerCLI C:\> get-vmhost myesxhostname | get-scsilun -canonicalname "naa.60a98000486e2f36584a5a4251596472" | set-scsilunpath -preferred $true
   
        
Set-ScsiLunPath : 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:138
+ get-vmhost usmasoh004v04.na.it-solutions.myatos.net | get-scsilun -canonicalname "naa.60a98000486e2f36584a5a4251596472" | set-scsilu
npath <<<<  -preferred $true
    + CategoryInfo          : InvalidArgument: (naa.60a98000486e2f36584a5a4251596472:PSObject) [Set-ScsiLunPath], ParameterBindingExc
   eption
    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetScsiLunPath

PowerCLI C:\> get-vmhost usmasoh004v04.na.it-solutions.myatos.net | get-scsilun -canonicalname "naa.60a98000486e2f36584a5a4251596472" |

set-scsilunpath  -scsilunpath fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.60a98000486e2f36584a5a4251

596472 -preferred $true

Set-ScsiLunPath : Cannot bind parameter 'ScsiLunPath'. Cannot convert the "fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:50

0a09828739792f-naa.60a98000486e2f36584a5a4251596472" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.Host.

Storage.Scsi.ScsiLunPath".

At line:1 char:152

+ get-vmhost myesxhost | get-scsilun -canonicalname "naa.60a98000486e2f36584a5a4251596472" | set-scsilu

npath  -scsilunpath <<<<  fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f-naa.60a98000486e2f36584a5a42515964

72 -preferred $true

    + CategoryInfo          : InvalidArgument: (:) [Set-ScsiLunPath], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetScsiLunPath

PowerCLI C:\> get-vmhost usmasoh004v04.na.it-solutions.myatos.net | get-scsilun -canonicalname "naa.60a98000486e2f36584a5a4251596472" |

set-scsilunpath  -scsilunpath vmhba0 -preferred $true

Set-ScsiLunPath : Cannot bind parameter 'ScsiLunPath'. Cannot convert the "vmhba0" value of type "System.String" to type "VMware.VimAu

tomation.ViCore.Types.V1.Host.Storage.Scsi.ScsiLunPath".

At line:1 char:152

+ get-vmhost myesxhost | get-scsilun -canonicalname "naa.60a98000486e2f36584a5a4251596472" | set-scsilu

npath  -scsilunpath <<<<  vmhba0 -preferred $true

    + CategoryInfo          : InvalidArgument: (:) [Set-ScsiLunPath], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetScsiLunPath

thank you for the help so far
Mike

Reply
0 Kudos
CRad14
Hot Shot
Hot Shot
Jump to solution

Right, as I mentioned above, I believe the path should be

Get-datastore| Get-scsilun | Get-scsilunpath

Then you should be able to pass it to set-scsilunpath. Also at any point with any of these cmdlets you can stop to do some filtering... Whether it is adding the -canonical parameter to the get-scsilun, or even passing them to a Where-Object before being passed to the Set-Scsilun cmdlet

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want to filter on the HBA, you could do something like this

Get-VMHost myesxhostname | Get-VMHostHba | where {$_.Device -eq "vmhba1"}| Get-ScsiLun

This will return all the LUNs connected to that HBA.

For a specific LUN, you can do

Get-VMHost myesxhostname | Get-VMHostHba | where {$_.Device -eq "vmhba1"}|

Get-ScsiLun -CanonicalName "naa.60a98000486e2f36584a5a4251596472"

And to get the available paths for that LUN

Get-VMHost myesxhostname | Get-VMHostHba | where {$_.Device -eq "vmhba1"}|

Get-ScsiLun -CanonicalName "naa.60a98000486e2f36584a5a4251596472" |

Get-ScsiLunPath

This will return all paths for that LUN through vmhba1.

Now if you want to make 1 of those paths the preferred path, you will have to have a selection mechanism in place.

For example, to make the 1st path the preferred one, you could do

Get-VMHost myesxhostname | Get-VMHostHba | where {$_.Device -eq "vmhba1"}|

Get-ScsiLun -CanonicalName "naa.60a98000486e2f36584a5a4251596472" |

Get-ScsiLunPath | Select -First 1 |

Set-ScsiLunPath -Preferred $true

Or if you want to make a specific path the preferred path, you could do

Get-VMHost myesxhostname | Get-VMHostHba | where {$_.Device -eq "vmhba1"}|

Get-ScsiLun -CanonicalName "naa.60a98000486e2f36584a5a4251596472" |

Get-ScsiLunPath | where {$_.LunPath -eq "fc.20000000c97f2805:10000000c97f2805-fc.500a09808739792f:500a09828739792f--naa.60a98000486e2f36584a5a4251"} |

Set-ScsiLunPath -Preferred $true


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

Reply
0 Kudos
mprobst2011
Contributor
Contributor
Jump to solution

Your option that you think will only return the paths for one HBA actually returns the paths on all HBAs, it seems similar to what I was doing before trying to get just one path by using get-vmhosthba with teh device option, but it still returned all paths. the lun in question has 1 path on vmhba0 and 3 on vmhba1, and if I specify either hba, I get all 4 paths returned. but the last two options do work. Can you point me at some help on the "select" part of the statement? how would I use the option you gave here to select the 2nd path?

Get-VMHost myesxhostname | Get-VMHostHba | where {$_.Device -eq "vmhba1"}|

Get-ScsiLun -CanonicalName "naa.60a98000486e2f36584a5a4251596472" |

Get-ScsiLunPath | Select -First 1 |

Set-ScsiLunPath -Preferred $true

thanks

Mike

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is strange, the Get-ScsiLun cmdlet takes a HBA object from the pipeline.

You can get help for all the Select-Object parameters with

Get-Help Select-Object -Parameter *

To get the 2nd object, you could do

Select-Object -Index 1

Btw are you on PowerCLI 5.0.1 now ?


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

Reply
0 Kudos