VMware Cloud Community
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
notorious_bdg
Enthusiast
Enthusiast

I use this code I use to report info for all LUNs, vmfs and rdm. It includes the host LUN number plus much more. I'm not sure how to get the runtime name yet, but I question the usefulness in this report since the runtime name can be different on each ESX Server. If you add runtime name, you'll have to show it for each ESX Server with access to the LUN.

$RDMs = @()
foreach($vm in (Get-View -ViewType "VirtualMachine")) {
  foreach($dev in ($vm.Config.Hardware.Device | where {($_.gettype()).Name -eq "VirtualDisk"})) {
    if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or ($dev.Backing.CompatibilityMode -eq "virtualMode")) {
      $objRdm            = "" | select VMName, VMDK, UUID, DiskLabel, SCSIBus, SCSIDevice, Mode
      $objRdm.VMName     = $vm.Name
      $objRdm.VMDK       = $dev.Backing.FileName
      $objRdm.UUID       = $dev.Backing.LunUuid
      $objRdm.DiskLabel  = $dev.DeviceInfo.Label
      $objRdm.SCSIBus    = ( $vm.Config.Hardware.Device | ? { $_.Key -eq $dev.ControllerKey }).BusNumber
      $objRdm.SCSIDevice = $dev.UnitNumber
      $objRdm.Mode       = $dev.Backing.CompatibilityMode
      $RDMs += $objRdm
    }
  }
}
foreach ($cluster in (Get-View -ViewType "ClusterComputeResource")) {
  $vmhostsview = $cluster.host | % { Get-View $_ }
  $vmhostview  = $vmhostsview | Select -first 1
  $ScsiLuns    = $vmhostsview | % { $_.Config.StorageDevice.ScsiLun } | Select -unique *
  $UUIDs       = $ScsiLuns | Select -unique UUID
  $Datastores  = $vmhostsview | % { $_.Config.FileSystemVolume.MountInfo } | % { $_.Volume } | Select -Unique *
  $HostLUN     = $vmhostsview | % { $_.Config.StorageDevice.ScsiTopology.Adapter } | % { $_.Target | % { $_.LUN } } | Select -unique *
  foreach ($UUID in $UUIDs) {
    $Lun = $ScsiLuns | ? { $_.UUID -eq $UUID.UUID } | Select -first 1
    $objVolume               = "" | Select Cluster, VolumeName, CanonicalName, DisplayName, VolumeType, CapacityGB, BlockSizeMb, VMFSVersion, LunType, Vendor, Model, HostLUN, VM, VMDiskLabel, VMSCSIBus, VMSCSIDevice, Revision, ScsiLevel, UUID
    $objVolume.Cluster       = $cluster.Name
    $objVolume.CanonicalName = $Lun.CanonicalName
    $objVolume.HostLUN       = ($HostLUN | ? { $_.ScsiLun -eq $Lun.Key } | select -unique LUN).LUN
    $objVolume.UUID          = $Lun.Uuid
    $objVolume.CapacityGB    = $Lun.Capacity.Block * $Lun.Capacity.BlockSize / 1GB
    $objVolume.DisplayName   = $Lun.DisplayName
    $objVolume.LunType       = $Lun.LunType
    $objVolume.Vendor        = $Lun.Vendor
    $objVolume.Model         = $Lun.Model
    $objVolume.Revision      = $Lun.Revision
    $objVolume.ScsiLevel     = $Lun.ScsiLevel
    foreach ($vol in $Datastores) {
      if ($vol.extent | % { $_.diskname -eq $Lun.CanonicalName}) {
        $objVolume.VolumeName  = $vol.Name
        $objVolume.BlockSizeMb = $vol.BlockSizeMb
        $objVolume.VMFSVersion = $vol.Version
        $objVolume.VolumeType  = "vmfs"
      }
    }
    foreach ($rdm in $RDMs) {
      if ($Lun.Uuid -eq $rdm.UUID) {
        $objVolume.VolumeName   = $rdm.VMDK
        $objVolume.VM           = $rdm.VMName
        $objVolume.VMDiskLabel  = $rdm.DiskLabel
        $objVolume.VMSCSIBus    = $rdm.SCSIBus 
        $objVolume.VMSCSIDevice = $rdm.SCSIDevice
        if ($rdm.Mode -eq "virtualMode" ) { $objVolume.VolumeType  = "rdm"  }
        if ($rdm.Mode -eq "physicalMode") { $objVolume.VolumeType  = "rdmp" }
      }
    }
    $objVolume
  }
}

Reply
0 Kudos
timmp
Enthusiast
Enthusiast

Thanks for these great scripts. I am using one of these scripts in a datacenter with multiple clusters. When the information is output via html, it adds multiple instances of the clusters. Is there a way to run this and designate the cluster to gather the desired datastore information? I have tried modifying to no avail. Also, can it be setup to do a sort by the HostLun or VolumeName? Here is my modified script:

  1. ---- Hosts Storage Information ----

if ($ShowHostStorageInfoProd){

Write-CustomOut "..Checking Hosts Storage Information"

$ShowHostStorage = @()

foreach ($cluster in (Get-View -ViewType ClusterComputeResource)) {

$vmhostsview = $cluster.host | % { Get-View $_ }

$vmhostview = $vmhostsview | Select -first 1

$ScsiLuns = $vmhostsview | % { $_.Config.StorageDevice.ScsiLun } | Select -unique *

$UUIDs = $ScsiLuns | Select -unique UUID

$Datastores = $vmhostsview | % { $_.Config.FileSystemVolume.MountInfo } | % { $_.Volume } | Select -Unique *

$HostLUN = $vmhostsview | % { $_.Config.StorageDevice.ScsiTopology.Adapter } | % { $_.Target | % { $_.LUN } } | select -unique *

foreach ($UUID in $UUIDs) {

$Lun = $ScsiLuns | ? { $_.UUID -eq $UUID.UUID } | Select -first 1

$objVolume = "" | Select Cluster, VolumeName, HostLUN, CanonicalName, DisplayName, VolumeType, CapacityGB, BlockSizeMb, VMFSVersion, LunType, Vendor, Model, Revision, ScsiLevel, UUID

$objVolume.Cluster = $cluster.Name

$objVolume.CanonicalName = $Lun.CanonicalName

$objVolume.HostLUN = ($HostLUN | ? { $_.ScsiLun -eq $Lun.Key } | select -unique LUN).LUN

$objVolume.UUID = $Lun.Uuid

$objVolume.CapacityGB = $Lun.Capacity.Block * $Lun.Capacity.BlockSize / 1GB

$objVolume.DisplayName = $Lun.DisplayName

$objVolume.LunType = $Lun.LunType

$objVolume.Vendor = $Lun.Vendor

$objVolume.Model = $Lun.Model

$objVolume.Revision = $Lun.Revision

$objVolume.ScsiLevel = $Lun.ScsiLevel

foreach ($vol in $Datastores) {

if ($vol.extent | % { $_.diskname -eq $Lun.CanonicalName}) {

$objVolume.VolumeName = $vol.Name

$objVolume.BlockSizeMb = $vol.BlockSizeMb

$objVolume.VMFSVersion = $vol.Version

$objVolume.VolumeType = "vmfs"

}

}

$ShowHostStorage += $objVolume

}

If (($ShowHostStorage | Measure-Object).count -ge 0) {

$MyReport += Get-CustomHeader "Production Host Storage Detailed Information" "The following provides a detailed list of the Hosts and LUNs presented to the Hosts in a Cluster"

$MyReport += Get-HTMLTable $ShowHostStorage

$MyReport += Get-CustomHeaderClose

}

}

}

Reply
0 Kudos
LucD
Leadership
Leadership

To select a sprecific cluster you can modify this line

foreach ($cluster in (Get-View -ViewType ClusterComputeResource)) {

into

foreach ($cluster in (Get-View -ViewType ClusterComputeResource -Filter @{"Name"="myClusterName"})) {

To sort the results you can change this line

$MyReport += Get-HTMLTable $ShowHostStorage

into this

$MyReport += Get-HTMLTable ($ShowHostStorage | Sort-Object -Property HostLUN)

or

$MyReport += Get-HTMLTable ($ShowHostStorage | Sort-Object -Property VolumeName)

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
timmp
Enthusiast
Enthusiast

Can't thank you enough. The lump on my forehead was starting to grow. Smiley Happy

Worked perfectly!!!

Reply
0 Kudos
Mivian2
Contributor
Contributor

Thanks for these scripts...

I ran it against our clusters and because we have some LUNs mapped to the cluster but not used as vmfs or rdms we got odd results. Basically we got false positives on one of the if statements causing the wrong volume name etc...

I have reversed the test to a negative test and this seems to have sorted the issue. The clip below doesnt do anything is positive however you might want to set the Volume name to "Unused" or something.

if ($vol.extent | % { $_.diskname -ne $Lun.CanonicalName}) {

#Do Nothing

} ELSE {

$objVolume.VolumeName = $vol.Name

$objVolume.BlockSizeMb = $vol.BlockSizeMb

$objVolume.VMFSVersion = $vol.Version

$objVolume.VolumeType = $vol.Type

}

Thanks again

Regards

Mark

regards Mark
Reply
0 Kudos
LucD
Leadership
Leadership

My LUN report – datastore, RDM and node visibility has a script that shows all LUNs, irrespective if they are used as VMFS or RDM or even not used atll.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
wamatha
Contributor
Contributor

Ho do I export his to csv file?

Reply
0 Kudos
mburutzis
Contributor
Contributor

Did you get an answer for this? i am really bad at scripting and would like tis info also for this script in particular

Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

Which script are you talking about ?


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

Reply
0 Kudos
mburutzis
Contributor
Contributor

the one from notorious_bd

Reply
0 Kudos
LucD
Leadership
Leadership

Try the attached version


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

mburutzis
Contributor
Contributor

Awesome! You are the best!

Thank you very much!

Reply
0 Kudos
chaderic20
Contributor
Contributor

LucD, thanks for posting that script!  It's gotten me halfway to the report I'm trying to build.  I'm wondering if someone here can help me get the rest of the info I want.

I'm trying to build a report that has the following columns:  Host, VM, Disk Number, LUN ID, Runtime Name, Target, Status.  Using LucD's script as a starting point I've got a script that will give me the first 4 columns, but can't figure out where to get the Runtime Name, Target or Status.  Another problem is that this appears to only show each disk once, and I'm going to want each disk 4 times (once for each path - two HBA's, each dual pathed - because the runtime name will be different for each path).  My script is attached, any help you all can give me would be appreciated!  Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

To get the terminology clear, you mean RuntimeName, Target and Status as it appears on the View Paths panel in the vSphere Client ?


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

Reply
0 Kudos
chaderic20
Contributor
Contributor

Yes, that is correct.  Thanks!

Reply
0 Kudos
chaderic20
Contributor
Contributor

Here is my latest script for anyone who may find it useful.  I've added a couple more fields other than what my previous post said I was looking for.  And I never could find where to get the Target or Status fields, but my customer said that wasn't important, so I'm not too worried about getting it.  If anyone knows how/where to get those though, I'd still be interested in learning.

Reply
0 Kudos
Priergaard
Contributor
Contributor

Hi
I have tried to run your script, but report.csv is empty, what do I do wrong?

Best regards

Henrik Priergaard 

Reply
0 Kudos
chaderic20
Contributor
Contributor

Henrik,

Here is the most recent version of the script that I'm using.  There are a couple of lines you will need to change where I've removed my company's information and you'll have to put your company's information in.

In the line:

     Connect-VIServer -Server servername -WarningAction:SilentlyContinue

You will need to replace "servername" with the name of the vCenter server you want to connect to.  You will also need to run the script under a user account that has access to that vCenter server, or you will need to specifiy other credentials in the script.

In the line:

     foreach ($folder in (Get-View -ViewType "Folder" -Filter @{"Name" = "Folder name"}))

You will need to replace "Folder name" with the actual name of the folder you want to gather info from.  I only care about certain folders, so that is why I filter it down like that.  If you want to run the script against everything and not filter down to certain folders you can replace that entire for-loop with the lines:

     $Hosts += Get-View -ViewType "HostSystem"

     $VMs += Get-View -ViewType "VirtualMachine"

I think that should get you a report if you do that.  Let me know if you still have problems.

Chad

Reply
0 Kudos
AmolPatil
Enthusiast
Enthusiast

Hello Chad,

Its good script. But I am looking a script to get the selected VM or all the VMs who has DiskType -eq “RawPhysical”, details with Properties (Host, VM, DiskNumber, Identifier, Policy, VirtualDeviceNode, Capacity )

Can you assist ?

I tried this as below --

Function Get-RAWDiskInfo {

$RDisks = Get-VM $VM | Get-HardDisk | Where {$_.DiskType -eq “RawPhysical”}

Foreach ($RDisk in $RDisks) {

$Lun = Get-VMHost -name (Get-VM $VM).VMHost | Get-SCSILun $RDisk.SCSICanonicalName

$Props = @{ 'VM Name' = $RDisk.Parent;

            'DiskType' = $RDisk.DiskType;

            'Name' = $RDisk.Name;

            'Filename' = $RDisk.Filename;

            'Scsi Name' = $RDisk.ScsiCanonicalName;

            'LUN ID' = $Lun.RuntimeName.Substring($Lun.RuntimeName.LastIndexof(“L”)+1)

         

            }

New-Object -TypeName PSObject -Property $props

}

}

Regards, Amol Patil VCP 5
Reply
0 Kudos
dskwared
VMware Employee
VMware Employee

LucD​, thanks for this script with the DisplayName added! It really helped me find the information I was looking for! Thank you!

Reply
0 Kudos