Home > Blogs > VMware PowerCLI Blog


Managing storage paths with PowerShell.

With the VI Toolkit (for Windows) we try to make easy-to-use cmdlets that any administrator with PowerShell knowledge can pick up and start managing and automating VMware almost right away. All of this takes time to develop, of course. But one of the nicest features of the toolkit is that you have complete access to the extremely powerful (if sometimes baffling) set of web service APIs, which means that you don’t have to wait for us to develop easy-to-use cmdlets in order to automate the things that matter most to you.

One request I’ve been hearing a lot lately is that people would like to automate configuration of storage paths. This tends to be most useful if you have lots of ESX hosts and lots of big expensive arrays to hold their VMs, but one aspect of storage path configuration can be very useful even if you don’t have a huge deployment. Hopefully this post will give you a few ideas of what’s possible.

Configuring storage paths through the web services in PowerShell turns out to be pretty easy, but before we talk about that I want to show how you do it in the VI Client. The first thing to do in the VI Client is navigate to a host and select the Configuration tab, then select the storage section.

Client1_3

Once you’ve done that, select a datastore and click Properties… This brings up a window like this one:

Client2_2

Now we click Manage Paths… to actually configure the paths.

Client3

Within this interface we can configure individual paths or set the path policy.

Now let’s see how to do the same thing in PowerShell. First, let’s log in. 

Command1

With native cmdlets it’s easy to manage more than one host at a time, because it’s usually completely transparent. With the web services interfaces, it’s generally best to deal with one host at a time. In the next window I load my host in preparation for configuring it.

Command2

Next I load my host’s StorageSystem. This is the object that contains all data relevant to LUNs and paths, and allows me to change their configurations. The first thing to do is to see what LUNs are available and what paths they have. Here’s how to do it:

Command3

As in my screenshots from the VI Client, I’m going to focus on my vmhba2:1:1 LUN, which has 2 paths, vmhba2:1:1 and vmhba2:2:1. Let’s set this LUN to use the experimental round-robin policy.

Command4

Let’s make sure the call worked:

Client4_2

Again, these ideas are just to get you thinking about what’s possible. Configuring a single HBA in this way is not very interesting since it’s pretty easy to do it in the client. Let’s suppose you wanted to set the round-robin policy on every LUN that had multiple paths. Here’s a script to do it:

If experimental status sounds intimidating to you, it’s easy to set another policy, such as the fixed policy. This example sets my vmhba2:1:1 LUN to a fixed policy, with vmhba2:2:1 as the preferred path (refer to Step 3 above to see the list of valid paths.)

There are many, many more possibilities here. If you want to learn more about them, you basically have two choices, first you can wait until we get these sorts of things into our cmdlet set (note that this is not scheduled for our first GA release) or you can get acquainted with our HostStorageSystem interfaces and start configuring your host’s storage today.

As always, download the VI Toolkit (for Windows) to get started today.

5 thoughts on “Managing storage paths with PowerShell.

  1. Eric Sloof

    Hi,
    After I execute the get-view command I keep running into the following error A parameter cannot be found that matches parameter name ‘VMware.VimAutomation.Client20.VMHostImpl’.

    Reply
  2. Carter Shanklin

    Are you using get-view $h.id? I think you might be using get-view $h. If you’re still having trouble you might try the forum (http://communities.vmware.com/community/developer/windows_toolkit).

    Reply
  3. Simon Catlin

    Spot on – this is what I’ve been searching for…. for days!

    Reply
  4. IronVarmint

    Wow, this is a lifesaver. We’ve been asked to change all of our 4.1 U2 hosts to round-robin from mru.
    I believe this is the data object we are manipulating: http://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.host.MultipathInfo.LogicalUnitPolicy.html
    For the record I’ve used reporting from the post below to capture pre/post snapshots. http://communities.vmware.com/thread/284093

    Reply
  5. Chittaranjan

    Hi,

    Can you please let me know as to ho do I check Storage dual paths for windows server through powershell.

    thanks

    Reply

Leave a Reply

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

*