Using PowerCLI to set multipath policy based on array model

powerclilogoGoing through all of your hosts and setting your multipathing policy manually through either the C# or the vSphere Web Client can certainly be a trying task.  Sure, if you have 2 or 3 hosts it might be alright, but anything above that and things start to get pretty monotonous really fast!  Also we have all known that if you need to perform the same task more than once it’s always better to script it – Firstly it creates consistency across your environment, secondly it saves you time, and thirdly it helps the economy as you are out buying coffee when normally you would be at your desk clicking….

So all that leads me to the following script…  For the most part the script does two things – first it gets a list of all of your LUNS associated with a host or group of hosts, second, it sets up your desired multipathing policy on those luns based on the model of array presenting them as well as marks paths as preferred if applicable…  That being said, I’ve only included a few different models inside the script below, to see a full list of models you can run “esxcli storage nmp satp rule list”  from the esxcli to list all of the models and integrate them into the script as you see fit.

So first off you can see that the script accepts a parameter – if you pass the string fixall with the call of the script it will just continue without prompts, otherwise, it asks you for a y/n answer.   Also, when setting a path policy to fixed you might want to specify a preferred path – you can see that I’ve set this up as vmhba1, just be sure to customize the script to your liking for your environment…

Again I don’t claim to be a Powershell/PowerCLI scriptmaster, so if you see any performance enhancements, problems, suggestions, concerns please use the comments section below to let me know… – Anyone can write a script, but it takes a community to make it a great script.

1 thought on “Using PowerCLI to set multipath policy based on array model”

  1. cslee@nildram.co.uk

    Hi Mike,

    We came across your script which would be very useful for a piece of work that we are going to do. vCenter is v5.0 U1, and the hosts are also v5.0U1. We have small issue when enumerating the datastore and also the lunpath. We attempted to to troubshoot this.

    Get-Datastore | select extensiondata.info
    returns a blank list
    we then inserted some further troubleshooting:
    Get-ScsiLunPath -scsilun $luns[0] | select extensiondata.adapter

    extensiondata.adapter also return a blank list.

    Thanks
    C

Leave a Comment

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

Scroll to Top