VMware Cloud Community
BaskervilleByte
Contributor
Contributor
Jump to solution

Need to retreive LUN as well as RDM info per vcenter...

Hi all,

I know this is old hat stuff as I saw an earlier blog which revolved around what I am trying to achieve here

So, I am trying to retrieve all RDM perennially reserved values per host per vcenter server

I think I have managed to make the script work in regards to it pulling the RawPhysical and RawVirtual disktype per vm and grab the unique values of these and then export these values to a .csv file

I have been asked however if I can also retrieve the LUN of each RDM, I have looked into how to get the LUN value however cannot see how I can place that within my current script

Any help would be much appreciated, script attached as I cant seem to paste into here

Many thanks in advance


					
				
			
			
				
			
			
			
			
			
			
			
		
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$VCenters = Get-Content VCenterServers.txt

$Cred = Get-Credential -UserName mjclark_a@computacenter.com -Message 'Enter Password for vCenter Servers'

foreach ($VC in $VCenters) {

    Write-Host 'Connecting to Vcenter Server '$VC -ForegroundColor Green

    Connect-VIServer -Server $VC -Credential $Cred


    foreach ($dc in Get-Datacenter) {

        foreach ($cluster in Get-Cluster -Location $dc) {

            foreach ($esx in Get-VMHost -Location $cluster) {

                foreach ($rdm in Get-VM -Location $esx | Get-HardDisk -DiskType RawPhysical, RawVirtual) {

                $esxcli = Get-EsxCli -VMHost $esx -V2

                $esxcli.storage.core.device.list.Invoke(@{device = "$($rdm.ScsiCanonicalName)" }) |

                    Select-Object @{N = 'Datacenter'; E = { $dc.Name } },

                    @{N = 'Cluster'; E = { $cluster.Name } },

                    @{N = 'VMHost'; E = { $esx.Name } },

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

                    @{N = 'HardDisk'; E = { $rdm.Name } },

                    @{N = 'CanonicalName'; E = { $rdm.ScsiCanonicalName } },

                    @{N = 'LUN'; E = { ($esxcli.storage.core.path.list.Invoke(@{device = $rdm.ScsiCanonicalName })).RuntimeName.Split('L')[1] } },

                    @{N = 'PereniallyReserved'; E = { $_.IsPerenniallyReserved } }

            }

        }

    }


    Write-Host 'Disconnecting from vCenter Server '$VC -ForegroundColor Cyan

    Disconnect-VIServer $VC -confirm:$false

}


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Isn't that what you have in $naa.
Or what do you mean by LUN?


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

0 Kudos
BaskervilleByte
Contributor
Contributor
Jump to solution

Hi LucD,

Thanks for replying, basically as well as the raw naa ref ID I also would like the LUNid decimal value stored in vcenter

I think the command to do this is something along the lines below,

get-scsilun -vmhost *.vmhost -canonicalname *.hddisplayname

*.runtimename.substring(*.runtimename.lastindexof("L")+1)

This I borrowed from a previous article:

https://communities.vmware.com/thread/514090

Apologies, as you can tell my powercli is extremely poor Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$VCenters = Get-Content VCenterServers.txt

$Cred = Get-Credential -UserName mjclark_a@computacenter.com -Message 'Enter Password for vCenter Servers'

foreach ($VC in $VCenters) {

    Write-Host 'Connecting to Vcenter Server '$VC -ForegroundColor Green

    Connect-VIServer -Server $VC -Credential $Cred


    foreach ($dc in Get-Datacenter) {

        foreach ($cluster in Get-Cluster -Location $dc) {

            foreach ($esx in Get-VMHost -Location $cluster) {

                foreach ($rdm in Get-VM -Location $esx | Get-HardDisk -DiskType RawPhysical, RawVirtual) {

                $esxcli = Get-EsxCli -VMHost $esx -V2

                $esxcli.storage.core.device.list.Invoke(@{device = "$($rdm.ScsiCanonicalName)" }) |

                    Select-Object @{N = 'Datacenter'; E = { $dc.Name } },

                    @{N = 'Cluster'; E = { $cluster.Name } },

                    @{N = 'VMHost'; E = { $esx.Name } },

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

                    @{N = 'HardDisk'; E = { $rdm.Name } },

                    @{N = 'CanonicalName'; E = { $rdm.ScsiCanonicalName } },

                    @{N = 'LUN'; E = { ($esxcli.storage.core.path.list.Invoke(@{device = $rdm.ScsiCanonicalName })).RuntimeName.Split('L')[1] } },

                    @{N = 'PereniallyReserved'; E = { $_.IsPerenniallyReserved } }

            }

        }

    }


    Write-Host 'Disconnecting from vCenter Server '$VC -ForegroundColor Cyan

    Disconnect-VIServer $VC -confirm:$false

}


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

0 Kudos
BaskervilleByte
Contributor
Contributor
Jump to solution

Thanks LucD, this worked perfectly!

0 Kudos