[PowerCLI] Change DefaultPSP and SATP/PSP for every lun on every host

Changing the default Path Selection Policy (PSP) on every host can be time consuming challenge, after that you also need to change the PSP on every lun on every host.
In the past you needed to SSH login to every host and change the settings “manually”, but there is also a PowerCLI way to do that. Using PowerCLI cmdlet Get-EsxCli you can execute the esxcli command from PowerCLI directly to the host. Using foreach to loop through all the hosts and check and change with Get-EsxCli the setting on every host and lun.
You can simply change the $VMW_SATP and $VMW_PSP for your required Storage Array Type Plugin (SATP) and Path Selection Policy (PSP), the script below is configured for IBM SVC-based systems (SVC, V7000, Actifio).

Code:

$VMW_SATP="VMW_SATP_SVC"
$VMW_PSP="VMW_PSP_RR"

$allVMhost = Get-VMHost | sort Name
foreach ($vmhost in $allVMhost){
	$esxcli = $vmhost | Get-EsxCli
	#Check VMW_SATP
	if ($esxcli.storage.nmp.satp.list() | where-object {$_.Name -eq $VMW_SATP -and $_.DefaultPSP -eq $VMW_PSP}){write-host "Default $VMW_SATP $VMW_PSP $vmhost correct"}
	else{$esxcli.storage.nmp.satp.set($null,$VMW_PSP,$VMW_SATP)}
    #VMW_SATP
	
	#Check VMW_PSP
	$psprrlun = $esxcli.storage.nmp.device.list() | where-object {$_.StorageArrayType -eq $VMW_SATP -and $_.PathSelectionPolicy -ne $VMW_PSP} | Select Device
	if ($psprrlun -eq $null){write-host "LUN setting $VMW_SATP $VMW_PSP $vmhost correct"}
	else{foreach ($lun in $psprrlun | foreach { $_.Device }){$esxcli.storage.nmp.device.set($null, $lun, $VMW_PSP)}}
	#VMW_PSP
}

Output:
ChangeSATP-PSP

Leave a Reply

Your email address will not be published. Required fields are marked *