VMware Cloud Community
GuilhermeAlves
Enthusiast
Enthusiast

Get Runtime, Lun Information from datastore

LucD

I've modified your script to bring me a bit more information... but still can't bring everything.

I'm having problem in a cluster and not all datastores are being viewed by the hosts. In really, i want to get this info: 

vCenter,Cluster,Vmhost,Datastore Names , Naaids , Lun Names, Lun Ids

I think i can retrieve all the info but when running the code below, i'm having this error:

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

Exceção ao chamar "Add" com "2" argumento(s): "Item has already been added.

Key in dictionary: 'key-vim.host.PlugStoreTopology.Adapter-vmhba2'  Key being

added: 'key-vim.host.PlugStoreTopology.Adapter-vmhba2'"

No linha:19 caractere:9

+         $HbaNames2.Add($_.Key,$HbaNames1.Item($_.Adapter))

+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentException

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

For sure i have duplicated disks added to some hbas..(i don´t know exactly why) but i want to bring that info, even duplicated. How could i do it?

Your function modified:

function Get-ScsiLunRuntime{
param(
  [parameter(valuefrompipeline = $true, mandatory = $true,
  HelpMessage = "Enter a host")]
  [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl[]]$VMHost,
  [switch]$Thin = $true
  )
    $HbaNames1 = @{}
    $HbaNames2 = @{}

$VMHost|%{
$currenthost = $_
    $teste = $currenthost | %{
       
      $_.ExtensionData.Config.StorageDevice.HostBusAdapter | %{
        $HbaNames1.Add($_.Key,$_.Device)
      }
      $_.ExtensionData.Config.StorageDevice.PlugStoreTopology.Adapter | %{
        $HbaNames2.Add($_.Key,$HbaNames1.Item($_.Adapter))
      }
      $_.ExtensionData.Config.StorageDevice.PlugStoreTopology.Path | %{
        $HbaNames2.Item($_.Adapter) + ":C" + $_.ChannelNumber + ":T" + $_.TargetNumber + ":L" + $_.LunNumber
      }
    }
    $output=@()
    $teste|%{
   
        $a = "" | select Vmhost, Runtimename
        $a.Vmhost = $currenthost
        $a.Runtimename = $_

        $output +=$a
   
    }
     $output | %{$_}
    }
}

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

Just to make sure we are looking at the same script, which script of mine are you referring to ?


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

Reply
0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast

I was referring this:Runtime Name via Extensiondata and New-VIProperty | LucD notesLucD notes

Buuut after some checks and rechecks i've found my answer. Here it is:

$vmhosts = $cluster|Get-VMHost
foreach($Vmhost in $vmhosts){
      $allOut = @()
      $Vmhost.ExtensionData.Config.StorageDevice |%{
       $storageDevice = $_
            #Path loop
            $storageDevice.PlugStoreTopology.Path|%{
            $path = $_
                #HBA loop
                $storageDevice.HostBusAdapter|%{
                    $hba = $_
                    $output = "" | select Vmhost,Hba,WWN,LunNumber,PathName
                    $output.Vmhost = $vmhost.Name
                    $output.Hba = $hba.Device
                    $PWWN = $hba.PortWorldWideName
                    $NWWN = $hba.NodeWorldWideName
                    $WWN = "$PWWN $NWWN"
                    $output.WWN = $WWN
                    $output.LunNumber = $path.LunNumber
                    $output.PathName = $path.Name
                    $allOut += $output
                 }#end hbas loop
             }#end Paths loop      
       }#end StorageDevices loop
}#end vmhosts loop

$allOut |Export-csv -Path "C:\temp\teste.csv" -NoTypeInformation -useculture

I'm not sure if it's retrieving everything as i wanted.

studying the algorithm ´-´

Reply
0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast

Eureka!

Finally i could get the results i wanted. After all, i just get the naa, wwn and device info from the path extracted from VMhost properties. 😃

Here is the result:

https://communities.vmware.com/docs/DOC-26069

Reply
0 Kudos
LucD
Leadership
Leadership

Great !

I was just going to reply, sorry for the delay Smiley Sad


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

Reply
0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast

No problem, thanks for the concern. I was just thinking the alternative you would show me ! Smiley Happy

--- Mensagem Original ---

De: "LucD" <communities-emailer@vmware.com>

Enviado: 25 de março de 2014 17:21

Para: "GuilhermeAlves" <guilhermestela@hotmail.com>

Assunto: New message: "Get Runtime, Lun Information from datastore"

VMware Communities<https://communities.vmware.com/index.jspa>

Get Runtime, Lun Information from datastore

created by LucD<https://communities.vmware.com/people/LucD> in VMware vSphere™ PowerCLI - View the full discussion<https://communities.vmware.com/message/2361403#2361403>

Reply
0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast

so...there's no more discussion anymore, i think....i've answered myself hehehehe

What can we do with this discussion?

Reply
0 Kudos