Josito
Contributor
Contributor

list disks rdm with powershell

Hello ,

i like how lists disk rdm of a vm .Command get-hardisk give me location vmdk , capacity , but i want more informatation disks RDMs

Por example , i want to list imformation like vmhba 1:0:9:0 , SCSI (2:1) , etc for each disk .

Someone can gime some help

Thanks

50 Replies
LucD
Leadership
Leadership

This gives the devicename of each RDM disk for each vm.

$report = @()
$vms = Get-VM | Get-View
foreach($vm in $vms){
  foreach($dev in $vm.Config.Hardware.Device){
    if(($dev.gettype()).Name -eq "VirtualDisk"){
	  if($dev.Backing.CompatibilityMode -eq "physicalMode"){
	    $row = "" | select VMName, HDDeviceName, HDFileName
          $row.VMName = $vm.Name
	    $row.HDDeviceName = $dev.Backing.DeviceName
	    $row.HDFileName = $dev.Backing.FileName
	    $report += $row
	  }
	}
  }
}
$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
munizaba
Contributor
Contributor

Hi LucD,

Can you please check attached Script since is not producing any result.

Regards,

0 Kudos
LucD
Leadership
Leadership

Could it be that there are no raw disks ?

Perhaps try without the test for "physicalMode".

$report = @() 
$vms = Get-VM | Get-View 
foreach($vm in $vms) {
			foreach($dev in $vm.Config.Hardware.Device)	{
				if(($dev.gettype()).Name -eq "VirtualDisk")	{ 
#					if($dev.Backing.CompatibilityMode -eq "physicalMode"){ 
						$row = "" | select VMName, HDDeviceName, HDFileName 
						$row.VMName = $vm.Name 
						$row.HDDeviceName = $dev.Backing.DeviceName 
						$row.HDFileName = $dev.Backing.FileName 
							$report += $row 
					} 	
#				} 
			} 
} 
$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
munizaba
Contributor
Contributor

Thanks mate, is working now:

$report = @()

$vms = Get-VM | Get-View

foreach($vm in $vms) {

foreach($dev in $vm.Config.Hardware.Device) {

if(($dev.gettype()).Name -eq "VirtualDisk") {

$row = "" | select VMName, HDDeviceName, HDFileName

$row.VMName = $vm.Name

$row.HDDeviceName = $dev.Backing.DeviceName

$row.HDFileName = $dev.Backing.FileName

$report += $row

}

}

}

$report

0 Kudos
LucD
Leadership
Leadership

Just came to realise that RDMs come in 2 flavours, physical and virtual.

Since I only tested for physical and your RDMs are probably in virtual compatibility mode they didn't show.

This script should only show RDMs but for both compatibility modes

$report = @()
$vms = Get-VM | Get-View
foreach($vm in $vms){
  foreach($dev in $vm.Config.Hardware.Device){
    if(($dev.gettype()).Name -eq "VirtualDisk"){
	  if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or 
	     ($dev.Backing.CompatibilityMode -eq "virtualMode")){
	    $row = "" | select VMName, HDDeviceName, HDFileName, HDMode
          $row.VMName = $vm.Name
	    $row.HDDeviceName = $dev.Backing.DeviceName
	    $row.HDFileName = $dev.Backing.FileName
	    $row.HDMode = $dev.Backing.CompatibilityMode
	    $report += $row
	  }
	}
  }
}
$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
brekus
Enthusiast
Enthusiast

This script is great. Just as an FYI, instead of looking for disks that are virtual or physical mode, I looked for disks that were not equal to flat.

0 Kudos
gboskin
Enthusiast
Enthusiast

Hi all ....

I was wondering how to add the RDM size to this table ??

Kind regards

0 Kudos
LucD
Leadership
Leadership

The answer is in


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
emmar
Hot Shot
Hot Shot

Hi,

This script is great is there a way to get it to output what ESX host the VMs are on?? Is there a property for the host within the $vm object??? something like $vm.Host??

Thanks

Emma

0 Kudos
LucD
Leadership
Leadership

Yes, the VirtualMachine object contains, under the Runtime.Host property, a MoRef to the host on which the VM is running or assigned.

The script could then be something like this:

$report = @()
$vms = Get-VM  | Get-View
foreach($vm in $vms){
  foreach($dev in $vm.Config.Hardware.Device){
    if(($dev.gettype()).Name -eq "VirtualDisk"){
	  if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or 
	     ($dev.Backing.CompatibilityMode -eq "virtualMode")){
	    $row = "" | select VMName, VMHost, HDDeviceName, HDFileName, HDMode, HDsize
          $row.VMName = $vm.Name
	    $row.VMHost = (Get-View $vm.Runtime.Host).Name
	    $row.HDDeviceName = $dev.Backing.DeviceName
	    $row.HDFileName = $dev.Backing.FileName
	    $row.HDMode = $dev.Backing.CompatibilityMode
           $row.HDSize = $dev.CapacityInKB
	    $report += $row
	  }
	}
  }
}
$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
emmar
Hot Shot
Hot Shot

Thanks LucD

Thats great! And a useful link so hopefully i can work more out for myself!

E

0 Kudos
AlbertWT
Virtuoso
Virtuoso

thanks man, this is such a useful script !

Kind Regards,

AWT

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
TCronin
Expert
Expert

Does anyone know how to add the device name to the output? For example, instead of just the vmhba notitation, can you also get something like this:

EMC Fibre Channel Disk (naa.60060480000190100744533031393736)

Thanks!

Tom Cronin, VCP, VMware vExpert 2009 - Co-Leader Buffalo, NY VMUG

Tom Cronin, VCP, VMware vExpert 2009 - 2021, Co-Leader Buffalo, NY VMUG
0 Kudos
LucD
Leadership
Leadership

I suspect you are after the DisplayName as it's called in the SDK Reference.

Try this script, the DisplayName has been added.

$report = @()
$vms = Get-VM | Get-View
foreach($vm in $vms){
	foreach($dev in $vm.Config.Hardware.Device){
		if(($dev.gettype()).Name -eq "VirtualDisk"){
			if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or 
			($dev.Backing.CompatibilityMode -eq "virtualMode")){
				$row = "" | select VMName, VMHost, HDDeviceName, HDFileName, HDMode, HDsize, HDDisplayName
				$row.VMName = $vm.Name
				$esx = Get-View $vm.Runtime.Host
				$row.VMHost = ($esx).Name
				$row.HDDeviceName = $dev.Backing.DeviceName
				$row.HDFileName = $dev.Backing.FileName
				$row.HDMode = $dev.Backing.CompatibilityMode
				$row.HDSize = $dev.CapacityInKB
				$row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).DisplayName
				$report += $row
			}
		}
	}
}
$report


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

jsenon
Contributor
Contributor

Thanks LucD.

Is it possible to add Runtime Name and Lun Name in the display of your script ?

(This data is available in VCenter 4, on manage Path of the RDM Disk)

Thanks in advance,

Regads,

0 Kudos
jsenon
Contributor
Contributor

Hi,

nobody have an idea ?

Thanks.

0 Kudos
zMarkz
Contributor
Contributor

This script is very helpful. I have trying to figure out how to add 'Runtime Name:' and 'Adpater:' information to this report.

Any thoughts on how to do this?

Thanks in advance.

-Mark

fc.200000e08b9bad3f:210000e08b9bad3f-fc.50060160c1e02ae9:5006016141e02ae9-naa.60060160efe01900c883b8dee114de11

Runtime Name: vmhba1:C0:T0:L22

Device: naa.60060160efe01900c883b8dee114de11

Device Display Name: DGC Fibre Channel Disk (naa.60060160efe01900c883b8dee114de11)

Adapter: vmhba1 Channel: 0 Target: 0 LUN: 22

Adapter Identifier: fc.200000e08b9bad3f:210000e08b9bad3f

Target Identifier: fc.50060160c1e02ae9:5006016141e02ae9

Plugin: NMP

State: active

Transport: fc

Adapter Transport Details: WWNN: 20:00:00:e0:8b:9b:ad:3f WWPN: 21:00:00:e0:8b:9b:ad:3f

Target Transport Details: WWNN: 50:06:01:60:c1:e0:2a:e9 WWPN: 50:06:01:61:41:e0:2a:e9

0 Kudos
Michelle_Laveri
Virtuoso
Virtuoso

Handy script. Did anyone manage to work out how to report lun number and vmhba path...

The script currently gives:

VMName : ctx01

VMHost : esx1.corp.com

HDDeviceName : vml.020000000060a9800050334c77465a5256777954344c554e202020

HDFileName : ctx01/ctx01_1.vmdk

HDMode : physicalMode

HDsize : 10485760

HDDisplayName : NETAPP Fibre Channel Disk (naa.60a9800050334c77465a525677795434)

But I was hoping to see -

LUNnumber : 102

VMhbapath: vmhba1:0:102

Any ideas?

Regards

Mike Laverick

RTFM Education

http://www.rtfm-ed.co.uk

Author of the SRM Book:http://stores.lulu.com/rtfm

Free PDF or at-cost Hard Copy

Regards
Michelle Laverick
@m_laverick
http://www.michellelaverick.com
0 Kudos
lamw
Community Manager
Community Manager

This should be pretty trivial by pulling out deviceName property, I'm sure Luc or Alan could help with pulling that out as well.

Here is a vSphere SDK for Perl script that utilizes this property to displays the vmhba path and you can extract the LUN # from that as well.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos