VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

List RDM LUN ID from a VM

Hi All,

I am not able to get the LUN ID of the RDM`s of the VM through Powercli

From the below script, I am able to get the following details but not the LUN ID. These RDMs are craved from EMC VNX and assigned to VMs.

Get-VM vm1 | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName, CapacityGB | fl

Output :

Parent        : vm1
Name          : Hard disk 3
DiskType      : RawPhysical

ScsiCanonicalName : naa.6000144000000010706334e594fc67d8

DeviceName    : vml.02001700006000144000000010706334e594fc67d8496e76697378
CapacityGB    : 200

From GUI, I can see the LUN ID as 23, Edit VM Setting > Select RDM  > Manage Paths > Where I can see the LUN ID of the RDM. I would like to retrieve the LUN ID from Powercli.

Please Help.

-Madhu

Reply
0 Kudos
1 Solution

Accepted Solutions
pdvtetzel
Contributor
Contributor
Jump to solution

There you go

@"

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

Title: rdm.ps1

Description: get all VMs with RDM.

Usage: .\rdm.ps1

Date: 10/20/2104

Author: Sascha Tetzel

Output:

VMName        : ntsv2.xxx.local

VMHost        : psvi08.xxx.local

HDDeviceName  : vml.02001c00006001438005de7f650000700002ed0000485356343530

HDName        : Harddisk 7

HDFileName    : [prod02] ntsv2.xxx.local/ntsv2_6.vmdk

HDMode        : physicalMode

HDsize        : 1024

HDDisplayName : naa.6001438005de7f650000700002ed0000

LUN           : 28

VMName        : pvsdb03.xxx.local

VMHost        : psvi10.xxx.local

HDDeviceName  : vml.02001d0000600508b40010735100011000023e0000485356343530

HDName        : Harddisk 2

HDFileName    : [prod02] pvsdb03.xxx.local/pvsdb03_1.vmdk

HDMode        : virtualMode

HDsize        : 260

HDDisplayName : naa.600508b40010735100011000023e0000

LUN           : 29

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

"@

add-pssnapin VMware.VimAutomation.Core

Connect-VIServer -Server vcenter

$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, HDName, HDFileName, HDMode, HDsize, HDDisplayName, LUN                   

                $row.VMName = $vm.Name                   

                $esx = Get-View $vm.Runtime.Host                   

                $row.VMHost = ($esx).Name                   

                $row.HDDeviceName = $dev.Backing.DeviceName

                $row.HDName = $dev.DeviceInfo.Label                 

                $row.HDFileName = $dev.Backing.FileName                   

                $row.HDMode = $dev.Backing.CompatibilityMode                   

                $row.HDSize = [system.math]::Round($dev.CapacityInKB / 1048576)

                $row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).CanonicalName

                $lun = Get-ScsiLun -VmHost $row.VMHost -CanonicalName $row.HDDisplayName

                $row.LUN = $lun.RuntimeName.SubString($lun.RuntimeName.LastIndexof("L")+1)

                $report += $row

            }

         }

    }

}

$report

View solution in original post

Reply
0 Kudos
7 Replies
pdvtetzel
Contributor
Contributor
Jump to solution

Hi,

try this:

@"

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

Title: rdm.ps1

Description: get all VMs with RDM.

Usage: .\rdm.ps1

Date: 10/20/2104

Author: Sascha Tetzel

Output:

VMName        : ntsv2.xxx.local

VMHost        : psvi08.xxx.local

HDDeviceName  : vml.02001c00006001438005de7f650000700002ed0000485356343530

HDFileName    : [prod02] ntsv2.xxx.local/ntsv2_6.vmdk

HDMode        : physicalMode

HDsize        : 1073741824

HDDisplayName : naa.6001438005de7f650000700002ed0000

LUN           : 28

VMName        : pvsdb03.xxx.local

VMHost        : psvi10.xxx.local

HDDeviceName  : vml.02001d0000600508b40010735100011000023e0000485356343530

HDFileName    : [prod02] pvsdb03.xxx.local/pvsdb03_1.vmdk

HDMode        : virtualMode

HDsize        : 272629760

HDDisplayName : naa.600508b40010735100011000023e0000

LUN           : 29

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

"@

add-pssnapin VMware.VimAutomation.Core

Connect-VIServer -Server pvsvc01

$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, LUN                    

                $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}).CanonicalName

                $lun = Get-ScsiLun -VmHost $row.VMHost -CanonicalName $row.HDDisplayName

                $row.LUN = $lun.RuntimeName.SubString($lun.RuntimeName.LastIndexof("L")+1)

                $report += $row

            }

         }

    }

}

$report

im sorry there was an copy and paste Error 😉

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thanks for your quick reply. I am getting the below error when I run

PowerCLI C:\> .\LUNID1.ps1

At C:\LUNID1.ps1:2 char:38

+ $vms = Get-VM | Get-View foreach($vm in $vms) {

+                                      ~~

Unexpected token 'in' in expression or statement.

At C:\LUNID1.ps1:2 char:37

+ $vms = Get-VM | Get-View foreach($vm in $vms) {

+                                     ~

Missing closing ')' in expression.

At C:\LUNID1.ps1:2 char:45

+ $vms = Get-VM | Get-View foreach($vm in $vms) {

+                                             ~

Unexpected token ')' in expression or statement.

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : UnexpectedToken

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank You very much Smiley Happy. After little editting in the script, it worked.

Anyway to change the size of disk from KB to GB ?

Reply
0 Kudos
pdvtetzel
Contributor
Contributor
Jump to solution

yes sorry copy and paste... you know 😉

change $row.HDSize to:

$row.HDSize = [system.math]::Round($dev.CapacityInKB / 1048576)

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect, that worked. One last thing.

How do I get Harddisk3, Harddisk4.......... of the RDM which they are connected to VM

Reply
0 Kudos
pdvtetzel
Contributor
Contributor
Jump to solution

There you go

@"

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

Title: rdm.ps1

Description: get all VMs with RDM.

Usage: .\rdm.ps1

Date: 10/20/2104

Author: Sascha Tetzel

Output:

VMName        : ntsv2.xxx.local

VMHost        : psvi08.xxx.local

HDDeviceName  : vml.02001c00006001438005de7f650000700002ed0000485356343530

HDName        : Harddisk 7

HDFileName    : [prod02] ntsv2.xxx.local/ntsv2_6.vmdk

HDMode        : physicalMode

HDsize        : 1024

HDDisplayName : naa.6001438005de7f650000700002ed0000

LUN           : 28

VMName        : pvsdb03.xxx.local

VMHost        : psvi10.xxx.local

HDDeviceName  : vml.02001d0000600508b40010735100011000023e0000485356343530

HDName        : Harddisk 2

HDFileName    : [prod02] pvsdb03.xxx.local/pvsdb03_1.vmdk

HDMode        : virtualMode

HDsize        : 260

HDDisplayName : naa.600508b40010735100011000023e0000

LUN           : 29

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

"@

add-pssnapin VMware.VimAutomation.Core

Connect-VIServer -Server vcenter

$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, HDName, HDFileName, HDMode, HDsize, HDDisplayName, LUN                   

                $row.VMName = $vm.Name                   

                $esx = Get-View $vm.Runtime.Host                   

                $row.VMHost = ($esx).Name                   

                $row.HDDeviceName = $dev.Backing.DeviceName

                $row.HDName = $dev.DeviceInfo.Label                 

                $row.HDFileName = $dev.Backing.FileName                   

                $row.HDMode = $dev.Backing.CompatibilityMode                   

                $row.HDSize = [system.math]::Round($dev.CapacityInKB / 1048576)

                $row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).CanonicalName

                $lun = Get-ScsiLun -VmHost $row.VMHost -CanonicalName $row.HDDisplayName

                $row.LUN = $lun.RuntimeName.SubString($lun.RuntimeName.LastIndexof("L")+1)

                $report += $row

            }

         }

    }

}

$report

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very very much Smiley Happy

This worked perfectly as needed.

Reply
0 Kudos