PowerCLI

 View Only
Expand all | Collapse all

All LUNs assigned to ESXs

LucD

LucDFeb 24, 2012 08:09 AM

xacolabril

xacolabrilFeb 24, 2012 08:16 AM

  • 1.  All LUNs assigned to ESXs

    Posted Feb 22, 2012 09:29 AM

    Hello,
        I want to know certain information about a virtual infrastructure. By example:

    "ESX Host","LUN Id","Capacity","Type"
    "ESX1","12","400 GB","Flat"
    "ESX2","12","400 GB","Flat"
    "ESX1","15","250 GB","Flat"
    "ESX2","15","250 GB","Flat"
    "ESX1","25","100 GB","vRDM"
    "ESX1","33","200 GB","pRDM"

    Or best for me:

    "ESX Host","LUN Id","Capacity","Type","Datastore?"
    "ESX1","12","400 GB","Flat","DataStore_1"
    "ESX2","12","400 GB","Flat","DataStore_1"
    "ESX1","15","250 GB","Flat","DataStore_2"
    "ESX2","15","250 GB","Flat","DataStore_2"
    "ESX1","25","100 GB","vRDM","N/A"
    "ESX1","33","200 GB","pRDM","N/A"


    Is it popssible?

    Thank you

    Best regards.



  • 2.  RE: All LUNs assigned to ESXs

    Posted Feb 22, 2012 09:38 AM

    Hi,

    I assume you want the details of datastore as u mention in your example.

    So yes you can get the same if you are having handson in SQL

    Go to vcenter database and there are two table which will give you the output you required

    ie

    select * from dbo.VPX_DATASTORE
    select * from dbo.VPX_DATASTORE_INFO



  • 3.  RE: All LUNs assigned to ESXs

    Posted Feb 22, 2012 01:26 PM

    DONT use the database for this.  Its not document (or supported) for this purpose, for a reason (they DO change it between releases).

    You DO want to use the API for this.

    Check out some of the healthcheck and inventory scripts posted in this group that should get you close.  Also, check out RVTools - it has an export option like this.



  • 4.  RE: All LUNs assigned to ESXs

    Posted Feb 22, 2012 05:04 PM

    Have a look at my LUN report – datastore, RDM and node visibility post.

    The script in there should retrieve most of the info you're after.



  • 5.  RE: All LUNs assigned to ESXs

    Posted Feb 22, 2012 05:38 PM

    This is what I came up with... Although I couldn't find the LUN number anywhere..

    $output=@()
    ForEach($vmhost in (get-vmhost))
    {
    ForEach($datastore in ($vmhost|get-datastore)){
    $dat=""| Select -property VMhost, Name, Capacitygb, Type, ID
    $dat.vmhost=$vmhost.name
    $dat.name=$datastore.name
    $dat.capacitygb=$datastore.capacitygb
    $dat.type=$datastore.extensiondata.summary.type
    $dat.id=$datastore.id
    $output+=$dat
    }}
    $output|FT -autosize

    Let me know



  • 6.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 08:03 AM

    Hello.

    • UmesjAhuja >> Thank you. Yes, I can see info, but I can't see RDM LUNs (only VMFS)....

    • mcowger >> oh yes. You're right, it's best for me in PowerCli ,too...

    • LucD >> Yes, I found your article from internet, but after test it, I can see some errors in the execution. So I commented this post on the forum. I can see some errors that:

    Cannot index into a null array.
    At C:\TEMP\LucDScript.ps1:40 char:39
    +       $scsiTab[$key] = $scsiTab[$key][ <<<< 0], $dsName, $scsiTab[$key][2]
        + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    • CRad14 >> Thank youI'm testing the script, but only says VMFS (not RDMs).


  • 7.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 08:09 AM

    Are your LUNs FC ?



  • 8.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 08:16 AM

    Yes Luc. Only FC LUNs.. :smileysad:?



  • 9.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 08:36 AM

    There must be a datastore that sits on a LUN (?) that is not listed by the Get-ScsiLun cmdlet (although I don't understand why that would happen).

    Would you mind running the following and check if produces any output ?

    Just set the clustername and then run.

    $clusName = "YourCluster" 
    $scsiTab
    = @{} $esxServers = Get-Cluster $clusName | Get-VMHost | Sort-Object -Property Name $esxServers | %{     $esxImpl = $_ # Get SCSI LUNs
        $esxImpl | Get-ScsiLun | where {$_.LunType -eq "Disk"} | %{         $key = $esxImpl.Name.Split(".")[0] + "-" + $_.CanonicalName.Split(".")[1]         if(!$scsiTab.ContainsKey($key)){             $scsiTab[$key] = $_.CanonicalName,"",$_.CapacityMB         }     } # Get the VMFS datastores
       
    $esxImpl | Get-Datastore | where {$_.Type -eq "VMFS"} | Get-View | %{         $dsName = $_.Name         $_.Info.Vmfs.Extent | %{             $key = $esxImpl.Name.Split(".")[0] + "-" + $_.DiskName.Split(".")[1]             if(!$scsiTab.ContainsKey($key)){                 Write-Host "Key not found $key"
                }         }     } }


  • 10.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 09:11 AM

    I ran the script after modify cluster name parameter, but I can see some errors that:

    The term 'if!$scsiTab.ContainsKey' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the n
    ame, or if a path was included, verify that the path is correct and try again.
    At C:\TEMP\f.ps1:21 char:36
    +             if!$scsiTab.ContainsKey <<<< ($key){
        + CategoryInfo          : ObjectNotFound: (if!$scsiTab.ContainsKey:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException



  • 11.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 09:14 AM

    Some parenthesis got lost during the copy/paste, I corrected the code above.

    Please try again.



  • 12.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 09:44 AM

    Thanks again Luc. In our cluster we have two ESX hosts (ESX 4.1 U1). I retrieve:

    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST1
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2
    Key not found ESXHOST2



  • 13.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 10:12 AM

    Ok, it looks as if the canonicalname is not picked up correctly.

    Can you do a

    Get-VMHost | Get-ScsiLun | Select CanonicalName

    and check if these names have a layout like 'naa.123...' ?

    And also check if the disknames the datastore extents have a similar layout ?

    Get-Datastore | %{

      $_.ExtensionData.Info.Vmfs.Extent | Select Diskname

    }



  • 14.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 10:32 AM

    Ok Luc. I can see the next:

    Get-VMHost | Get-ScsiLun | Select CanonicalName

    Always retrieves naa.(...) id's. By example:

    naa.60060e80056554000000655400000024
    naa.6006016005bc1d00a9a170a6ed9edf11
    naa.6006016086452100ae8f5d274d43dd11
    naa.60060e800565540000006554000000a1
    naa.60060160864521009e020f3a4943dd11
    naa.60060e80056554000000655400000064
    naa.6006016005bc1d0033319b89ed9edf11

    But the second execution, retrieves another thing:

    Get-Datastore | %{

      $_.ExtensionData.Info.Vmfs.Extent | Select Diskname

    }

    naa.60060480000290100756533030303433
    naa.60060480000290100756533030303544
    naa.60060480000290100756533030303737
    naa.60060480000290100756533030303931
    naa.60060480000290100756533030304142
    naa.60060480000290100756533030304446
    vmhba0:0:0
    naa.60060480000290100756533030313333
    naa.60060480000290100756533030313337
    naa.60060480000290100756533030313342
    naa.60060480000290100756533030313346
    vmhba0:0:0
    vmhba0:0:0
    naa.60060480000290100756533030384642
    naa.60060480000290100756533030374636
    naa.60060480000290100756533030393030
    naa.60060480000290100756533030304335
    vmhba0:0:0
    vmhba0:0:0
    vmhba0:0:0
    vmhba0:0:0
    vmhba1:3:165
    vmhba1:3:166
    vmhba1:3:167
    vmhba1:3:168
    vmhba1:3:174
    vmhba1:3:175
    vmhba1:3:176



  • 15.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 11:00 AM

    That seems to indicate you have some datastores on local storage or iSCSI storage.

    Is that correct ?

    Could you now run this

    Get-Datastore |
    Select @{N="Shared";E={$_.Extensiondata.Summary.MultipleHostAccess}},
    @{N="LUNs";E={[string]::Join(',',($_.ExtensionData.Info.Vmfs.Extent | %{$_.DiskName}))}}


  • 16.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 11:19 AM

    Hello Luc, we only have FC and local Storage (not iSCSI...). We have vCenter 4.1 U1, ESX's on 4.1 U1 and 3.5 U5..

    An extract of execution:

    Shared LUNs
    ------ ----
       True naa.60060480000290100756533030303433
       True naa.60060480000290100756533030303544
       True naa.60060480000290100756533030303737
       True naa.60060480000290100756533030303931
       True naa.60060480000290100756533030304142
       True naa.60060480000290100756533030304446
      False vmhba0:0:0
       True naa.60060480000290100756533030313333,naa.600604800002901007565330303133...
      False vmhba0:0:0
      False vmhba0:0:0
       True naa.60060480000290100756533030384642
       True naa.60060480000290100756533030374636,naa.60060480000290100756533030393030
       True naa.60060480000290100756533030304335
      False vmhba0:0:0
      False vmhba0:0:0
      False vmhba0:0:0
      False vmhba0:0:0
       True vmhba1:3:165,vmhba1:3:166,vmhba1:3:167,vmhba1:3:168,vmhba1:3:174,vmhba1...
       True vmhba1:3:139,vmhba1:3:92,vmhba1:3:93,vmhba1:3:94,vmhba1:3:95,vmhba1:3:9...
      False vmhba0:0:0
       True naa.60060480000290100756533030383032
       True naa.60060480000290100756533030383036



  • 17.  RE: All LUNs assigned to ESXs
    Best Answer

    Posted Feb 24, 2012 12:06 PM

    Ok, I updated my script with a couple of fail-safes.

    And I threw in the LUNid.

    Have a go with the attached script.



  • 18.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 12:41 PM

    Luc, Works very fine, now. One question about:

    I can see that script not works for clusters with ESX 3.5 hosts. Inly for 4.x... On the other hand, is it not possible to launch for only one ESX?

    Best regards.



  • 19.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 01:35 PM

    The problem with the 3.x servers is due to the way theyr return the LUN info.

    To get a report for a single ESX  server, try changing this line

    $esxServers = Get-Cluster $clusName | Get-VMHost | Sort-Object -Property Name

    into this

    $esxServers = Get-VMHost MyEsx


  • 20.  RE: All LUNs assigned to ESXs

    Posted Feb 24, 2012 02:00 PM

    Thank you so much, again.

    Best regards and nice weekend.