malabelle
Enthusiast
Enthusiast

SET SCSI-LUN preferredpath

Hi,

I'm completely lost.

I need to be able to create a datastore on clusters.

I alson need to be able to set a prefered path. But the prefered path won't work

Add-PSSnapin "Vmware.VimAutomation.Core"

$Vcenter = $Args[0]
$ClusterName = $Args[1]

Connect-VIserver $Vcenter | Out-Null


$VMHost = Get-Cluster $ClusterName | Get-VMHost | Select -First 1
$VMHostRes = Get-Cluster $ClusterName | Get-VMHost

$Name = $Args[2]
$Path = $Args[3]
$PrefPath = $Args[4]
Get-VMHost $VMHost | New-Datastore -Server $Vcenter -Name $Name -Path $Path -Vmfs -Confirm:$false

Get-VMHostStorage -VMHost $VMHostRes -Refresh

Get-SCSILUN -CanonicalName $Path -vmhost $VMHostRes | Set-SCSILun -PreferredPath $PrefPath -confirm:$false

I tried:

vmhba0:0:1:34

vmhba0:0:1

vmhba0:C0:T1

vmhba0:C0:T1:L34

It gives me this error:

Set-ScsiLun : 3/1/2011 11:47:59 AM    Set-ScsiLun        The preferred path you're trying to set is not a path to this scsi lun.
At C:\Skynet\Scipts\POWERCLI\DataStoreCreateForCluster.ps1:17 char:66
+ Get-SCSILUN -CanonicalName $Path -vmhost $VMHostRes | Set-SCSILun <<<<  -PreferredPath $PrefPath -confirm:$false
    + CategoryInfo          : InvalidArgument: (:) [Set-ScsiLun], InvalidArgument
    + FullyQualifiedErrorId : Client20_StorageServiceImpl_AssertPathIsFromTheSameLun_DifferentLun,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetScsiLun

What is the Prefered path it expects exactly?

any idea?

vExpert '16, VCAP-DCA, VCAP-DCD
0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership

Hi,

the PreferredPath parameter of the Set-ScsiLun cmdlet needs a value of type ScsiLunPath as is returned by the Get-ScsiLunPath cmdlet. I made some changes to your script to make it more efficient. And at least give it a valid value of the Preferredpath.

Add-PSSnapin "Vmware.VimAutomation.Core" 
param($Vcenter,$ClusterName,$Name, $Path, $PrefPath)

Connect-VIserver $Vcenter | Out-Null

$Cluster = Get-Cluster -Name $ClusterName
$VMHostRes = $Cluster | Get-VMHost
$VMHost = $VMHostRes | Select-Object -First 1 

$VMHost | New-Datastore -Server $Vcenter -Name $Name -Path $Path -Vmfs -Confirm:$false

Get-VMHostStorage -VMHost $VMHostRes -Refresh

$ScsiLun = Get-SCSILUN -CanonicalName $Path -vmhost $VMHostRes
$ScsiLunPath = Get-ScsiLunPath -ScsiLun $ScsiLun | Select-Object -First 1
$ScsiLun | Set-SCSILun -PreferredPath $ScsiLunPath -confirm:$false


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
malabelle
Enthusiast
Enthusiast

[vSphere PowerCLI] C:\Skynet\Scipts\POWERCLI> .\DataStoreSetPreferredPath.ps1 eagateway.ealab.psp EA1 noname "naa.6005076309ffc5650000000000000002" "fc.5001438004c1415d:5001438004c1415c-fc.5005076
309ffc565:5005076309130565-naa.6005076309ffc5650000000000000002"
Get-ScsiLun : 3/3/2011 10:18:37 AM    Get-ScsiLun        Could not find ScsiLunInterop with CanonicalName 'naa.6005076309ffc5650000000000000002'.
At C:\Skynet\Scipts\POWERCLI\DataStoreSetPreferredPath.ps1:14 char:23
+ $ScsiLun = Get-SCSILUN <<<<  -CanonicalName $Path -vmhost $VMHostRes
    + CategoryInfo          : ObjectNotFound: (naa.6005076309ffc5650000000000000002:String) [Get-ScsiLun], VimException
    + FullyQualifiedErrorId :

Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun

CanonicalN ConsoleDeviceName              LunType    CapacityMB MultipathPolicy
ame
---------- -----------------              -------    ---------- ---------------
naa.600... /vmfs/devices/disks/naa.600... disk           153600 Fixed

-----

#Add-PSSnapin "Vmware.VimAutomation.Core"

$Vcenter = $Args[0]
$ClusterName = $Args[1]

Connect-VIserver $Vcenter | Out-Null

$Name = $Args[2]
$Path = $Args[3]
$PrefPath = $Args[4]

$Cluster = Get-Cluster -Name $ClusterName
$VMHostRes = $Cluster | Get-VMHost
$VMHost = $VMHostRes | Select-Object -First 1

#$VMHost | New-Datastore -Server $Vcenter -Name $Name -Path $Path -Vmfs -Confirm:$false

#Get-VMHostStorage -VMHost $VMHostRes -Refresh

$ScsiLun = Get-SCSILUN -vmhost $VMHostRes -LunType disk
$ScsiLunPath = Get-ScsiLunPath -ScsiLun $ScsiLun | Select-Object -First 1
$ScsiLun | Set-SCSILun -ScsiLunPath $ScsiLunPath -confirm:$false

vExpert '16, VCAP-DCA, VCAP-DCD
0 Kudos
malabelle
Enthusiast
Enthusiast

ok, so I found what I need.

$ScsiLunPath = Get-ScsiLunPath -ScsiLun (Get-SCSILUN -CanonicalName naa.6005076309ffc5650000000000000002 -vmhost esxprod.ealab.psp) | Where {$_.Name -
eq "fc.5001438004c1415d:5001438004c1415c-fc.5005076309ffc565:5005076309130565-naa.6005076309ffc5650000000000000002"}

echo $scsiLunPath

Name       SanID                                    State      Preferred
----       -----                                    -----      ---------
fc.5001... 50:05:07:63:09:13:05:65                  Standby    False


Set-ScsiLunPath -ScsiLunPath $scsilunpath -Preferred $true

Name       SanID                                    State      Preferred
----       -----                                    -----      ---------
fc.5001... 50:05:07:63:09:13:05:65                  Active     True

Now when I put it in my script, it says:

Get-ScsiLun : 3/3/2011 10:50:45 AM    Get-ScsiLun        Could not find ScsiLunInterop with CanonicalName 'naa.6005076309ffc5650000000000000002'.
At C:\Skynet\Scipts\POWERCLI\DataStoreSetPreferredPath.ps1:20 char:53
+ $ScsiLunPath = Get-ScsiLunPath -ScsiLun (Get-SCSILUN <<<<  -CanonicalName $Path -vmhost $VMHostRes) | Where {$_.Name -eq "$PrefPath"}
    + CategoryInfo          : ObjectNotFound: (naa.6005076309ffc5650000000000000002:String) [Get-ScsiLun], VimException
    + FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun

Set-ScsiLunPath : Cannot validate argument on parameter 'ScsiLunPath'. The argument is null. Supply a non-null argument and try the command again.
At C:\Skynet\Scipts\POWERCLI\DataStoreSetPreferredPath.ps1:21 char:29
+ Set-ScsiLunPath -ScsiLunPath <<<<  $ScsiLunPath -Preferred $true
    + CategoryInfo          : InvalidData: (:) [Set-ScsiLunPath], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetScsiLunPath

vExpert '16, VCAP-DCA, VCAP-DCD
0 Kudos
malabelle
Enthusiast
Enthusiast

Ok, so now it works.

Add-PSSnapin "Vmware.VimAutomation.Core"

$Vcenter = $args[0]

Connect-VIserver $Vcenter | Out-Null

$VMHost = $args[1]
$CanName = $args[2]
$PrefPath = $args[3]
$ScsiLunPath = Get-ScsiLunPath -ScsiLun (Get-SCSILUN -CanonicalName $CanName -vmhost $VMHost ) | Where {$_.Name -eq $PrefPath}

Set-ScsiLunPath -ScsiLunPath $ScsiLunPath -Preferred $true

#where

#$vcenter = vcenter.domain

#VMHost = esxhost.domain

#$CanName = "naa.6005076309ffc5650000000000000002"

#$PrefLunPath = "fc.5001438004c1415f:5001438004c1415e-fc.5005076309ffc565:5005076309184565-naa.6005076309ffc5650000000000000002"

vExpert '16, VCAP-DCA, VCAP-DCD
0 Kudos