mercredi 16 mars 2016

Getting and Setting Multipathing in VMware vCenter using Powershell

Once in a while, when you first install or replace an external storage attached to your ESXi hosts the Multipathing Policy may need to be changed to something like Round Robin. While one may do it manually it can quickly become annoying after the second ESXi!

PowerShell combined with PowerCLI can solve this easily!


Retrieving the Multipathing Policy in a Cluster:


Building a report to retrieve the attached disks information is not that difficult, the Get-ScsiLun commandlet allows us to retrieve the list of all storage attached to the ESXi hosts thanks to the -LunType disk switch.

# Get all the Host present in the VMware Cluster "CL-LAB" and retrieve the attached disks

Get-Cluster -Name "CL-LAB" `

    | Get-VMHost `

    | Get-ScsiLun -LunType disk `

    | Select VMHost, CanonicalName, Vendor, CapacityGB, IsLocal, MultipathPolicy `

    | Sort-Object CanonicalName, VMHost `

    | Format-Table -AutoSize


<#

    VMHost              CanonicalName                        Vendor   CapacityGB IsLocal MultipathPolicy

    ------              -------------                        ------   ---------- ------- ---------------

    esx001.katalykt.lan naa.60002ac0000000000000002600032154 3PARdata        400   False      RoundRobin

    esx002.katalykt.lan naa.60002ac0000000000000002600032154 3PARdata        400   False      RoundRobin

    esx001.katalykt.lan naa.60002ac0000000000000002700032154 3PARdata        800   False           Fixed

    esx002.katalykt.lan naa.60002ac0000000000000002700032154 3PARdata        800   False           Fixed

    esx001.katalykt.lan naa.600507605809207819f3c23e2183f629 IBM         278,875    True           Fixed

    esx002.katalykt.lan naa.60050760408ed348188ad3f7419e64f3 IBM         278,875    True           Fixed

#>



Setting the Multipathing Policy in a Cluster:


Changing the Multipathing Policy is basically the same as the previous example aside from the fact that we do specify that the disk shouldn't be local (i.e SAN-based storage) and that the existing Policy should be different than Round Robin.

Note that it's important to use the -WhatIf switch with the Set-Scsilun commandlet first to measure the impact before executing it!

<#

    Get all the Host present in the VMware Cluster "CL-LAB", retrieve the attached disks and

    set the Multipath Policy on RoundRobin wherever a non-local, non-RoundRobin disk is detected

    WhatIf should be used first to validate the operation

#>

Get-Cluster -Name "CL-LAB" `

    | Get-VMHost `

    | Get-ScsiLun -LunType disk `

    | Where-Object { ($_.MultipathPolicy -notlike "RoundRobin") -and (-not($_.IsLocal)) } `

    | Set-ScsiLun -MultiPathPolicy RoundRobin -WhatIf


<#

    What if: Performing operation 'Updating ScsiLun.' on ScsiLun 'naa.60002ac0000000000000002700032154'

    What if: Performing operation 'Updating ScsiLun.' on ScsiLun 'naa.60002ac0000000000000002700032154'

#>

Aucun commentaire:

Enregistrer un commentaire