VMware Cloud Community
jSun311
Contributor
Contributor

Set the PSP on all datastores on a ESXi 4.1 host to VMW_PSP_FIXED_AP

I am trying to run this script 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" sinceVMW_PSP_FIXED_AP is already the default PSP for the SATP we are currently using).

Thanks for any help the community can provide here!

SCRIPT BEGIN

==============================================================

#Define Global Variables

$vcServer = "vSphere-Server"

$cluster = "ClusterName"

$psp = "VMW_PSP_FIXED_AP"

$satp = "VMW_SATP_ALUA_CX"

$vcCred = $Host.UI.PromptForCredential("Enter your vCenter Credentials", "Please enter your username and password in the DOMAIN\username format.", "", "")

$esxCred = $Host.UI.PromptForCredential("Enter the ROOT password for your ESXi hosts", "Enter the username and password here:", "", "")

#Begin with script execution [DO NOT EDIT BELOW THIS LINE]

#Connect to vCenter

Connect-VIServer $vcServer -Credential $vcCred | 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)

    }

    #Change the default PSP for my SATP

    $esxcli.nmp.satp.setdefaultpsp($psp,$satp)

    #Disconnect from the ESX host

    Disconnect-VIServer -Server $esxConnection -Confirm:$false

}

#Disconnect from vCenter

Disconnect-VIServer $vcServer -Confirm:$false | Out-Null

=====================================================================

SCRIPT END

Tags (3)
0 Kudos
1 Reply
LucD
Leadership
Leadership

Does this return all the devices that are used for your datastores ?

$esxcli.nmp.path.list()

Do you get any error messages ?


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

0 Kudos