VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
1 2 Previous Next 17 Replies Last post: Oct 31, 2009 1:08 PM by zMarkz  

list disks rdm with powershell posted: Sep 29, 2008 12:17 AM

Click to view Josito's profile Novice 14 posts since
Aug 23, 2005

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

Re: list disks rdm with powershell

1. Sep 29, 2008 1:16 AM in response to: Josito
Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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

Re: list disks rdm with powershell

2. Sep 30, 2008 8:10 PM in response to: LucD
Click to view munizaba@gmail.com's profile Enthusiast 27 posts since
Feb 18, 2007
Hi LucD,

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

Regards,

Attachments:

Re: list disks rdm with powershell

3. Sep 30, 2008 10:01 PM in response to: munizaba@gmai…
Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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

Re: list disks rdm with powershell

4. Sep 30, 2008 11:27 PM in response to: LucD
Click to view munizaba@gmail.com's profile Enthusiast 27 posts since
Feb 18, 2007

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


Re: list disks rdm with powershell

5. Oct 1, 2008 4:23 AM in response to: munizaba@gmai…
Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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

Re: list disks rdm with powershell

6. Dec 12, 2008 7:43 AM in response to: LucD
Click to view brekus's profile Hot Shot 100 posts since
Jan 17, 2008
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.

Re: list disks rdm with powershell

7. Jan 6, 2009 1:46 AM in response to: brekus
Click to view gboskin's profile Hot Shot 206 posts since
Nov 19, 2008

Hi all ....

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

Kind regards


Re: list disks rdm with powershell

8. Jan 6, 2009 2:04 AM in response to: gboskin
Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
The answer is in Get RDM size

Re: list disks rdm with powershell

9. Apr 22, 2009 6:04 AM in response to: LucD
Click to view emmar's profile Expert 354 posts since
May 9, 2005

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

Re: list disks rdm with powershell

10. Apr 22, 2009 6:20 AM in response to: emmar
Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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

Re: list disks rdm with powershell

11. Apr 22, 2009 7:15 AM in response to: LucD
Click to view emmar's profile Expert 354 posts since
May 9, 2005

Thanks LucD

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

E

Re: list disks rdm with powershell

12. Jun 18, 2009 8:00 PM in response to: LucD
Click to view AlbertWT's profile Expert 456 posts since
Apr 7, 2009

thanks man, this is such a useful script !

Kind Regards,
AWT

Re: list disks rdm with powershell

13. Sep 21, 2009 7:21 AM in response to: AlbertWT
Click to view TCronin's profile Expert 470 posts since
Nov 16, 2004

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

Re: list disks rdm with powershell

14. Sep 21, 2009 1:51 PM in response to: TCronin
Click to view LucD's profile Champion 2,430 posts since
Oct 31, 2005
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

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities