VMware Communities > VMTN > VMware vSphere™ > Automation Tools > vSphere™ PowerCLI > Discussions

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
Reply

list disks rdm with powershell

Sep 29, 2008 12:17 AM

Click to view Josito's profile Novice Josito 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

Reply Re: list disks rdm with powershell Sep 29, 2008 1:16 AM
Click to view LucD's profile Champion LucD 2,384 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
Reply Re: list disks rdm with powershell Sep 30, 2008 8:10 PM
in response to: LucD
Click to view munizaba@gmail.com's profile Enthusiast munizaba@gmail.com 27 posts since
Feb 18, 2007
Hi LucD,

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

Regards,

Attachments:
Reply Re: list disks rdm with powershell Sep 30, 2008 10:01 PM
in response to: munizaba@gmail.com
Click to view LucD's profile Champion LucD 2,384 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
Reply Re: list disks rdm with powershell Sep 30, 2008 11:27 PM
in response to: LucD
Click to view munizaba@gmail.com's profile Enthusiast munizaba@gmail.com 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


Reply Re: list disks rdm with powershell Oct 1, 2008 4:23 AM
in response to: munizaba@gmail.com
Click to view LucD's profile Champion LucD 2,384 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
Reply Re: list disks rdm with powershell Dec 12, 2008 7:43 AM
in response to: LucD
Click to view brekus's profile Hot Shot brekus 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.
Reply Re: list disks rdm with powershell Jan 6, 2009 1:46 AM
in response to: brekus
Click to view gboskin's profile Hot Shot gboskin 206 posts since
Nov 19, 2008

Hi all ....

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

Kind regards


Reply Re: list disks rdm with powershell Jan 6, 2009 2:04 AM
in response to: gboskin
Click to view LucD's profile Champion LucD 2,384 posts since
Oct 31, 2005
The answer is in Get RDM size
Reply Re: list disks rdm with powershell Apr 22, 2009 6:04 AM
in response to: LucD
Click to view emmar's profile Expert emmar 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

Reply Re: list disks rdm with powershell Apr 22, 2009 6:20 AM
in response to: emmar
Click to view LucD's profile Champion LucD 2,384 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
Reply Re: list disks rdm with powershell Apr 22, 2009 7:15 AM
in response to: LucD
Click to view emmar's profile Expert emmar 354 posts since
May 9, 2005

Thanks LucD

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

E

Reply Re: list disks rdm with powershell Jun 18, 2009 8:00 PM
in response to: LucD
Click to view AlbertWT's profile Expert AlbertWT 384 posts since
Apr 7, 2009

thanks man, this is such a useful script !

Kind Regards,
AWT

Reply Re: list disks rdm with powershell Sep 21, 2009 7:21 AM
in response to: AlbertWT
Click to view TCronin's profile Expert TCronin 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

Reply Re: list disks rdm with powershell Sep 21, 2009 1:51 PM
in response to: TCronin
Click to view LucD's profile Champion LucD 2,384 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
1 2 Previous Next
Actions