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
kumarsenthild
Enthusiast
Enthusiast

Big thanks to you. I am following you past 4 years.. When ever i am searching any script for PowerCli, at least google will provide your two scripts.

Now my requirement is need VM information with RDM status only ( RDM presented or not). Not required for RDM details. I have modified your script.

Request to review the script. i will believe i done some mistake.

@LucD

Regards Senthil Kumar D
Reply
0 Kudos
LucD
Leadership
Leadership

Try like this

$report = @()

$vmList = Get-Content C:\temp\VM.txt

$vms = Get-VM $vmList

foreach($vm in $vms){

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

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

       if($dev.Backing.CompatibilityMode -eq "physicalMode")

     {

$rdm = "yes"

        }

    else {

    $rdm = "no"

    }

$row = "" | select VMName, Cluster, ESXHost, Datastore, NetworkName, RDM

         $row.VMName = $vm.Name

$row.Cluster = get-cluster -VM $vm

         $row.ESXHost = Get-VMHost -VM $vm

$row.Datastore = Get-Datastore -VM $vm

         $row.NetworkName = (get-vm $vm | Get-NetworkAdapter).NetworkName

$row.RDM = $rdm

         $report += $row

     }

  }

}

$report


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

kumarsenthild
Enthusiast
Enthusiast

As Usually you are awesome Smiley Happy

Working like a charm.

Really appreciate your help.

Regards Senthil Kumar D
kumarsenthild
Enthusiast
Enthusiast

Hi LuCD,

One more help, after running this script i am getting multiple lines of same VM( Based on number of disk). Is it possible to display only one line for VM and need to add vCenter name in additional column. .

Regards Senthil Kumar D
Reply
0 Kudos
LucD
Leadership
Leadership

Have a look at 1.  Re: Get-HardDisk on one csv line


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

Reply
0 Kudos
kumarsenthild
Enthusiast
Enthusiast

Thanks. I will helpful. How i can add vCenter Name in Column. Before we are connecting two vCenter.

Regards Senthil Kumar D
Reply
0 Kudos
LucD
Leadership
Leadership

The vCenter can be derived from the Uid property on the HardDisk object.

Something like this

Get-VM -Name MyVM | Get-HardDisk |

Select Name,

    @{N='VM';E={$_.Parent.Name}},

    @{N='vCenter';E={$_.Uid.Split('@')[1].Split(':')[0]}}


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

dskwared
VMware Employee
VMware Employee

LucD, for the RDM-Report.ps1 script, is it possible to include a column that reports the Perennially Reserved status of each LUN?

Reply
0 Kudos
LucD
Leadership
Leadership

Since there are many version of the script floating around in this thread, would you mind attaching the one you are using?


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

Reply
0 Kudos
dskwared
VMware Employee
VMware Employee

Sorry, LucD​. Surprisingly, I actually figured this out on my own since posting the question. Here's what I pieced together for my particular needs:

$clusterName = 'ClusterName'
$cluster = Get-Cluster -Name $clusterName
$luns = Get-VM -Location $cluster | Get-HardDisk | where{$_.DiskType -match '^Raw'} | Select -ExpandProperty ScsiCanonicalName

Get-VMHost -Location $cluster | %{
$esxcli = Get-EsxCli -VMHost $_ -V2
$esxcli.storage.core.device.list.Invoke() | where{$luns -contains $_.Device} | Select @{N='VMHost';E={$esxcli.VMHost.Name}},Device,@{N='SizeGB';E={$_.Size/1KB}},IsPerenniallyReserved
}

This displayed a list of RDM disks, the ESXi host it is attached to, the size, and the Perennially Reserved status. Thanks for the ultra-fast reply (and for all you do for the VMware community!)

Reply
0 Kudos
LucD
Leadership
Leadership

Great, and thanks for sharing.


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

Reply
0 Kudos