Automation

 View Only
  • 1.  Need to retreive LUN as well as RDM info per vcenter...

    Posted Oct 01, 2020 02:33 PM

    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

    
                                                    


  • 2.  RE: Need to retreive LUN as well as RDM info per vcenter...

    Posted Oct 01, 2020 02:40 PM

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



  • 3.  RE: Need to retreive LUN as well as RDM info per vcenter...

    Posted Oct 01, 2020 02:58 PM

    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 :smileysad:



  • 4.  RE: Need to retreive LUN as well as RDM info per vcenter...
    Best Answer

    Posted Oct 01, 2020 03:50 PM

    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

    }



  • 5.  RE: Need to retreive LUN as well as RDM info per vcenter...

    Posted Oct 01, 2020 04:52 PM

    Thanks LucD, this worked perfectly!