Home > Blogs > VMware PowerCLI Blog


Listing RDMs and adding NFS datastores all over the place.

This post is going to cover some useful and popular recent content seen on our community. If you haven’t seen our community, it really is the best way to learn about PowerCLI and start getting automated. Today I’m going to touch on two topics. First, I’ll cover a script to list all RDM information, then give a script that will let you add NFS datastores to all your hosts in one shot.

Listing RDM Information

If you’re wondering what an RDM is or why you might use it, check out Rich Brambley’s blog for a really good explanation. Long story short is that RDMs are often used because you need to use Microsoft Cluster Services, or if you want to take advantages of features of your storage hardware.

In PowerCLI, RDMs will show up when you run the Get-HardDisk cmdlet. Specifically they will have a type of either “rawPhysical” or “rawVirtual”, depending on the type of RDM. However, they won’t have things like the SCSI LUN, which you may find very useful to report on. If you need this information, Luc Dekens has the script you’re looking for. It will list all RDMs on all VMs, along with their size, SCSI device, etc.

Adding NFS Datastores to Multiple vCenter or ESX Hosts

If you have more than a few hosts you probably have shared storage, this is what enables a lot of vSphere’s great features like vMotion. For this to work smoothly, however, you need that storage to be available on all your hosts in a consistent way, and this can turn in to quite a challenge as your environment grows.

Not long ago a question was asked about how to automate adding datastores across multiple vCenters. Not surprisingly, Luc also suggested an answer, and it’s a pretty good one. However I want to offer a slightly different answer. The first thing we should do is define all our NFS mapping information in a CSV file, like this:

VCName

DatastoreName

NfsHost

NfsExport

192.168.1.1

NFS1

10.24.1.1

/share

192.168.1.1

NFS2

10.24.1.2

/share

192.168.1.1

NFS3

10.24.1.3

/export

192.168.1.2

NFS1

10.24.1.1

/share

192.168.1.2

NFS2

10.24.1.2

/share

192.168.1.2

NFS3

10.24.1.3

/export

192.168.1.3

NFS1

10.24.1.1

/share

192.168.1.3

NFS2

10.24.1.2

/share

192.168.1.3

NFS3

10.24.1.3

/export

One great feature of PowerShell is its Import-Csv cmdlet, which will turn lines from a CSV file into objects that you can access just like any other object. My variation on Luc’s solution is to use the Group-Object cmdlet and group these entries by the VCName property. This way, if you’re adding multiple datastores to a single VC, you only have to log in once. Here’s my full solution to the problem, which assumes that you’ve saved your data into a file called nfs.csv.

Import-Csv nfs.csv | Group VCName | Foreach {
 Connect-VIServer -Server $_.Name
 Foreach ($entry in $_.Group) {
  Get-VMHost | New-Datastore -Nfs -Name $entry.DatastoreName `
   -Path $entry.NfsExport -NfsHost $entry.NfsHost
 }
}

Closing Thought

Be sure to check out our community, it really is the most valuable source of information for automating with PowerCLI.

One thought on “Listing RDMs and adding NFS datastores all over the place.

  1. Roger

    this is what I get:
    My command at the powershell prompt is:
    PS P:\> Import-Csv frc.csv | Group VCName | Foreach { Connect-VIServer -Server $
    _.Name Foreach ($entry in $_.Group) { Get-VMHost | New-Datastore -Nfs -Name $en
    try.DatastoreName ` -Path $entry.NfsExport -NfsHost $entry.NfsHost }}
    In red is spits out:
    Unexpected token ‘in’ in expression or statement.
    At line:1 char:98
    + Import-Csv frc.csv | Group VCName | Foreach { Connect-VIServer -Server $_.Nam
    e Foreach ($entry in

    Reply

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>