Script: Changing the Path Selection Policy

Posted by : on

Category : esx   howto   vmware   powershell   script   storage


Last week I had performed a semi-automatic (scripted) turn key installation. Before going out to the customer site, I had set the install script to set the SATP and the PSP for an Equallogic Array (SATP = VMW_SATP_EQL, PSP = DELL_PSP_EQL_ROUTED) during the installation. Unfortunately, I found out after the fact, that they had a Compellent Array. Because of this, I needed to change the SATP and the PSP (SATP = VMW_SATP_DEFAULT_AA, PSP = VMW_PSP_RR) for each of the existing LUNs and any future LUNs. I knew that I could do this with PowerCLI, but I didn’t feel like reinventing the wheel. A quick search found this site from “the Windows Server Guy” with a script that was basically ready to go. I modified the script a little for my environment. One of the biggest changes that I had to make was changing the Disk ID number from naa.5000 to naa.6000 for the Compellent Array.
Fun Fact: NAA stands for Network Addressing Authority identifier. EUI stands for Extended Unique Identifier. The number is guaranteed to be unique to a LUN. The NAA or EUI identifier is the preferred method of identifying LUNs and the number is generated by the storage device. Since the NAA or EUI is unique to the LUN, if the LUN is presented the same way across all ESX hosts, the NAA or EUI identifier remains the same.

##============================================================================== ##==============================================================================

SCRIPT………: pspchange.ps1

AUTHOR………: Scott Sarkan

MODIFIED BY….: Sam Aaron

EMAIL……….: sam.aaron@micronauts.us

VERSION……..: 1.0

DATE………..: 05/17/2012

LICENSE……..: Freeware

REQUIREMENTS…: Powershell v2.0

USAGE……….: ./pspchange.ps1

##

DESCRIPTION….: a script to change the psp policy of existing and new

datastores to RR

##

NOTES……….: Original Author: Scott Sarkan

(http://msserverguru.blogspot.com/2012/05/esxi5-change-multipath-policy-and.html)

##

SETUP……….:

##

CUSTOMIZE……:

##============================================================================== ##==============================================================================

##==============================================================================

SNAPINS

##============================================================================== if ((Get-PSSnapin -Name “VMware.VimAutomation.Core” -ErrorAction SilentlyContinue) -eq $null){ Add-PSSnapin -Name “VMware.VimAutomation.Core” } clear

##==============================================================================

VARIABLES

##============================================================================== $vcServer = “192.168.1.103” $cluster = “cluster1” $psp = “VMW_PSP_RR” $satp = “VMW_SATP_DEFAULT_AA” $DiskID = “naa.6000” # I had to change this from the original.

DO NOT MODIFY THE BELOW CODE

##==============================================================================

START ##============================================================================== #Prompt for Credentials $vcCred = $host.ui.PromptForCredential("VCENTER LOGIN", "Provide VCENTER credentials (administrator privileges)", "", "") $esxCred = $host.ui.PromptForCredential("ESX HOST LOGIN", "Provide ESX host credentials (probably root)", "root", "") #Connect to vCenter Connect-VIServer -Server $vcServer -Credential $vcCred #Set Roundrobin Policy on specified LUNs and Connect to ESX hosts for IOPS setting foreach ($esxhost in Get-Cluster $cluster | Get-VMHost) { write-output $esxhost.Name #host you are connecting to #Change Multipathing policy to RoundRobin Get-VMHost $esxhost |Get-ScsiLun -LunType "disk"|where {$_.MultipathPolicy -ne "RoundRobin"} | where {$_.CanonicalName -match $diskid}|Set-ScsiLun -MultipathPolicy "RoundRobin" #Connect to vCenter Connect-VIServer -Server $esxhost -Credential $esxCred #Connect to ESXcli $esxcli = Get-ESXcli #Go through each storage device where the ID begins with $Diskid $esxcli.storage.nmp.device.list() | where {$_.device -match $Diskid}| %{ #Capture the current configuration of the focused storage device $configBefore = $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) #Set the IOoperations limit using the currently focused naa ID $esxcli.storage.nmp.psp.roundrobin.deviceconfig.set(0,$configBefore.device,[long]1,"iops",$false) #Capture the configuration post the set $configAfter = $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get($_.device) #Returns $configBefore $configAfter } #Change the default PSP for the specified SATP $esxcli.nmp.satp.setdefaultpsp($psp,$satp) } #Disconnect from ESX hosts foreach ($esxhost in Get-Cluster $cluster | Get-VMHost) { Disconnect-VIServer -Server $esxhost.name -Confirm:$false } #Disconnect from vCenter Disconnect-VIServer $vcServer -Confirm:$false


About Sam Aaron
Sam Aaron

Father, Husband, Geek. Workaholic.

Email : mail@micronauts.us

Website : http://micronauts.us

About Sam Aaron

Father. Husband. Geek. Workaholic.

Star
Useful Links