How to get RDM (Raw Device Mappings) disks w/PowerCLi

Cover

This article, I want to open a series of articles the purpose of each of them is to cover one of PowerCLi functions or so-called cmdlets I wrote, designed to perform some tasks in the VMware virtual infrastructure, that cannot be fully accomplished using only built-in PowerCLi functions. All these functions are merged into one module – Vi-Module. You can read here how to use this module.

Get-RDM

  • Therefore, today’s function is Get-RDM or Get-ViMRDM.

  • Do not be surprised, each function in addition to its own name will have additional one with the -ViM suffix, indicating it belongs to the same module (Virtual infrastructure Module).

Import-Module Vi-Module –Force
Get-Command –Module Vi-Module
Get-Alias –Definition Get-RDM
  • It is no secret that VMware since time immemorial supports Raw Device Mapping. This technology allows the virtual machine through a special file located in a Datastore, to get direct access to the LUN.
  • There is a question. How to find all VM that have RDM disks, as well as to get them as much as possible the necessary, important and structured information? VMware offers for this purpose use the built-in Get-HardDisk cmdlet.

Get-Help Get-HardDisk -Online

LUN ID

  • The disadvantage of this method is that it does not provide the necessary parameter such a LUNID. In principle, it does not have to provide this information because Get-HardDisk takes as a parameter one or more virtual machines objects returned by Get-VM cmdlet, and virtual machine «does not have» such information. However, the ESXi server on which registered this machine «knows» so necessary for us the LUNID.
  • In the vSphere Client, you can see it as follows:

VM-> Edit Settings-> select Hard Disk with Mapped Raw LUN in the Summary-> Manage Paths.

01.Get-RDM_ManagePaths

  • In the new window, you will see your RAW disk’s LUNID:

02.Get-RDM_LunId

  • Why this parameter is so important? The fact that during manipulation with RAW disks of the same size, for example, when adding a disk in the vSphere Client (LUNID 24 and 25 on the below picture), or when you remove the LUN from your SAN, LUNID is the only parameter distinguishing different LUN. Of course, there may be cases when there are two or more LUN with the same LUNID, but this is a rare and does not reduce the importance of this parameter.

03.Get-RDM_AddRdm

Returned objects

  • Function Get-RDM, as it should any «right» PowerShell function does not return a text as well objects with that you can perform all standard objects’ operations: sorting Sort-Object, filtering Where-Object, export to a file Export-Csv and format Format-Table, Format-List, Format-Wide. The property names are self-explained.
$rep = Get-VM | Get-RDM
$rep | sort VM | ft –au
$rep | epcsv –notype .\RDM.csv
  • How does this apply in a practice? See the examples within the function:
Get-Help Get-RDM -Examples
  • I personally very often use the filter | Where-Object {$_.HDSizeGB -gt 1} to filter out the «service» disks smaller than 1GB, such as SRM server’s disks.
Get-VM | Get-RDM | ? {$_.HDSizeGB -gt 1}
  • With the Regex expression, the function expands the Datastore name from the VMDK file name.
  • Finally, the function visually displays the progress using Write-Progress with the current VM name and its RAW disk in the PowerCLi console. Even if you have filtered RAW disks on any criteria, the function will still show them in the console.

Summary

  • For more details about the function, please take a look at the content based help and examples.
Get-Help Get-RDM -Full
Get-Help Get-RDM -Examples
Get-Help Get-RDM -Parameter VM

You may also like:

VMware Vi-Module Home
VMware VSAN PowerCLi module
VMware VAMI PowerCLi module

7 thoughts on “How to get RDM (Raw Device Mappings) disks w/PowerCLi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s