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
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
I haven't used it myself yet, but this is directly from the set-scsilunpath help
Hope that helps!
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
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.
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
One way to get a specific lun/datastore would be
Get-datastore Volume3 | Get-scsilun | Get-scsilunpath
Gotta love the Pipe! #TWSS
it does not seem that the get-scsilun can use the output of get-datastore?
Which PowerCLI version are you running ?
With PowerCLI 5.0.1 this works
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am still running 4.1 u1, let me upgrade, I am getting closer though
... 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
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
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?
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 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
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
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
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
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