VMware Cloud Community
dougjef
Enthusiast
Enthusiast
Jump to solution

Set MultiPath Policy to VMW_PSP_FIXED_AP gets error

Hi, I'm running the following script and getting the error below

# Get information from user

$vc = Read-Host "Please enter the vCenter Server name:"
$uname = Read-Host "Please enter the username to connect to the vCenter server:"
$upass = Read-Host "Please enter the associated password:"
$clusterName = Read-Host "Please enter the Cluster name:"
Write-Host "Connecting to vCenter server $vc, please wait." -BackgroundColor Black -ForegroundColor White
Connect-VIserver $vc -user $uname -password $upass | Out-Null

###

# Retrieve ESX hosts in Cluster

$VMHosts = Get-Cluster $clusterName | Get-VMHost

# Run through this loop for each host in the cluster

foreach ($VMHost in $VMHosts)
{
$luns = @($VMHost|get-scsilun -luntype disk| where-object {$_.ConsoleDeviceName -like "/vmfs/devices/disks/naa*"} | Sort-Object CanonicalName)
$firstLUNPaths = Get-ScsiLunPath -ScsiLun $luns[0]
$numPaths = $firstLUNPaths.Length
$count = 0
foreach ($lun in $luns)
{
  if ($count -ge $numPaths)
  {
   $count = 0
  }
  $paths = @(Get-ScsiLunPath -ScsiLun $lun)
  $lun|Set-ScsiLun -MultipathPolicy VMW_PSP_FIXED_AP -PreferredPath $paths[$count]
  $count += 1
  # Sleep for 30 seconds to prevent array saturation.
  Start-Sleep -Seconds 30
}
}

Here is the error


Set-ScsiLun : Cannot bind parameter 'MultipathPolicy'. Cannot convert value "VM
W_PSP_FIXED_AP" to type "VMware.VimAutomation.ViCore.Types.V1.Host.Storage.Scsi
.ScsiLunMultipathPolicy" due to invalid enumeration values. Specify one of the
following enumeration values and try again. The possible enumeration values are
"Fixed, MostRecentlyUsed, RoundRobin, Unknown".
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\scripts\fixedp
olicy.ps1:31 char:36
+         $lun|Set-ScsiLun -MultipathPolicy <<<<  VMW_PSP_FIXED_AP -PreferredPa
th $paths[$count]
    + CategoryInfo          : InvalidArgument: (:) [Set-ScsiLun], ParameterBin
   dingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat
   ion.ViCore.Cmdlets.Commands.Host.SetScsiLun

It doesnt appear to like the VMW_PSP_FIXED_AP as the PSP, even though I can set it fine in the GUI. I'm running a Clariion CX4 and moving to this policy instead of round robin to get automatic failback of luns. Am I missing something? The script works fine if I use "FIXED" but I want to use VMW_PSP_FIXED_AP to take advantage of ALUA.

Any help would be greatly appreciated. Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, I see. In that case you can use the Get-EsxCli cmdlet.

See Arnim's post, called ESXCLI the PowerCLI, for a detailed description.


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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

The MultiPathPolicy parameter on the Set-ScsiLun cmdlet expects one of the values from the ScsiLunMultipathPolicy enumeration.

So your line should be

...
$lun|Set-ScsiLun -MultipathPolicy Fixed -PreferredPath $paths[$count]
...


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

Reply
0 Kudos
dougjef
Enthusiast
Enthusiast
Jump to solution

Thanks LucD

However, I dont want to use the FIXED  (vmware) policy since it isnt the recommended policy for ALUA enabled arrays.  The correct one is VMW_PSP_FIXED_AP. for EMC Clariion arrays based on their best practice document. I guess there is no way to choose the proper policy via the CLI?

I've attached the screenshot of the 4 options available in the GUI. I want to choose the top one.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, I see. In that case you can use the Get-EsxCli cmdlet.

See Arnim's post, called ESXCLI the PowerCLI, for a detailed description.


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

Reply
0 Kudos
dougjef
Enthusiast
Enthusiast
Jump to solution

Thanks LucD! Got it with your help. One thing to note, it appears that once this script is run it does require a reboot for the new PSP to take effect.

One more question, what is the best way to modify this script to only target hosts in maintenance mode in the cluster?

Thanks again.

Here is the working script

#Define some variables
$vcServer = "virtualcenter1"
$cluster = "Test"
$psp = "VMW_PSP_FIXED_AP"
$satp = "VMW_SATP_ALUA_CX"
$esxCred = Get-Credential

#Connect to vCenter
Connect-VIServer $vcServer | Out-Null

#Connect to ESX hosts in cluster
foreach ($esx in Get-Cluster $cluster | Get-VMHost) {
Connect-VIServer $esx -Credential $esxCred | Out-Null
}

#Retrieve the esxcli instances and loop through them
foreach($esxcli in Get-EsxCli) {

#Change PSP for my devices with 4 or more paths
$esxcli.nmp.path.list() | group-Object –Property Device | Where {$_.count –ge 4} | %{
  $esxcli.nmp.device.setpolicy($null, $_.Name, $psp) | Out-Null
}

#Change the default PSP for my SATP
$esxcli.nmp.satp.setdefaultpsp($psp,$satp) | Out-Null
}

#Disconnect from ESX hosts
foreach ($esx in Get-Cluster $cluster | Get-VMHost) {
Disconnect-VIServer $esx.name -Confirm:$false
}

#Disconnect from vCenter
Disconnect-VIServer $vcServer -Confirm:$false | Out-Null

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I would use a where-clause when getting the ESX hosts from the cluster.

And I would use 1 loop that runs through all the ESX servers one-by-one.

Something like this

#Define some variables 
$vcServer
= "virtualcenter1"
$cluster
= "Test"
$psp = "VMW_PSP_FIXED_AP"
$satp = "VMW_SATP_ALUA_CX"
$esxCred = Get-Credential

#Connect to vCenter
Connect-VIServer
$vcServer | Out-Null
#
Loop through all ESX hosts in the cluster thay are in maintenance mode
foreach
($esx in (Get-Cluster $cluster | Get-VMHost | where {$_.ConnectionState -eq "Maintenance"})) {     #Connect to the ESX host
    $esxConnection = Connect-VIServer $esx -Credential $esxCred     #Retrieve the esxcli instance
    $esxcli = Get-EsxCli -Server $esxConnection
   
#Change PSP for my devices with 4 or more paths
    $esxcli.nmp.path.list() | group-Object –Property Device | Where {$_.count –ge 4} | %{         $esxcli.nmp.device.setpolicy($null, $_.Name, $psp) | Out-Null
    }     #Change the default PSP for my SATP
   
$esxcli.nmp.satp.setdefaultpsp($psp,$satp) | Out-Null
   
#Disconnect from the ESX host
    Disconnect-VIServer -Server
$esxConnection -Confirm:$false
}
#Disconnect from vCenter
Disconnect-VIServer
$vcServer -Confirm:$false | Out-Null


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

Reply
0 Kudos
jSun311
Contributor
Contributor
Jump to solution

I am trying to run this in my ESXi 4.1 environment and it is not looping through all the datastores bound to the hosts in the cluster we are running this against.  Ultimately, we need to change the PSP on all datastores to "VMW_PSP_FIXED_AP".

What would I need to change so that the script loops through each and every datastore on the host and changes the PSP to VMW_PSP_FIXED_AP (basically "Fixed" since VMW_PSP_FIXED_AP is already the default PSP for the SATP we are currently using).

Thanks for any help the community can provide here!

-jSun311

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The multi-pathing setting is done on LUNs/devices, not on datastores.

You would need to find the LUNs/devices that are used for your datastores.

Then you could run the script above only for those devices.


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

Reply
0 Kudos