VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Vendor column shows blank

Hi,

I am unable to get the Vendor details of the volume, as it shows blank

Please help....

Script

#Script

$clus = "Compute"

$date = Get-Date -format dd-MMM-yyyy

$csvName = "d:\reports\Free_LUNs_Info_$date.xlsx"

$rndNum = Get-Random -Maximum 99999

$LunInfoDef = @"

    public string ClusterName;

    public string CanonicalName;

    public string Vendor;

    public string UsedBy;

    public string DSC;

    public string SizeGB;

"@

$LunInfoDef = "public struct LunInfo" + $rndNum + "{`n" + $LunInfoDef

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

$esxServers | %{

    $LunInfoDef += ("`n`tpublic string " + ($_.ExtensionData.config.Network.DnsConfig.Hostname) + ";")

}

$LunInfoDef += "`n}"

Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

$scsiTab = @{}

$esxServers | %{

    $esxImpl = $_

# Get SCSI LUNs

    if(([Version]$esxImpl.Version).Major -lt 6){

      $esxImpl | Get-ScsiLun | where {$_.LunType -eq "Disk"} | %{

     

          $key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.CanonicalName.Split(".")[1]

          if(!$scsiTab.ContainsKey($key)){

              $lunId = $_.RuntimeName.Split('L')[1]

              $scsiTab[$key] = $_.CanonicalName,"",$_.CapacityGB,$lunId,""

          }

      }

    }

    Else{

      $esxImpl.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object{$_.LunType -eq 'disk'} |%{

          $key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.CanonicalName.Split(".")[1]

          $capacityGB = $_.Capacity.Block * $_.Capacity.BlockSize / 1GB

          $lunUuid = $_.Uuid

          $lun = $esxImpl.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object{$_.Id -eq $lunUuid}

          $lunId = $lun.Path[0].Name.Split('L')[1]

          $scsiTab[$key] = $_.CanonicalName,"",$capacityGB,$lunId,""

      }

    }

# Get the VMFS datastores

    $esxImpl | Get-Datastore | Where-Object {$_.Type -eq "VMFS"} | Get-View | %{

        $dsName = $_.Name

        $dscName = ''

        if($_.Parent.Type -eq 'StoragePod'){

            $dscName = Get-View -Id $_.Parent -Property Name -Server $esxImpl.Uid.Split('@')[1].Split(':')[0] | Select -ExpandProperty Name

        }

        $_.Info.Vmfs.Extent | %{

            $key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.Split(".")[1]

            $scsiTab[$key][1] = $dsName

            $scsiTab[$key][4] = $dscName

        }

    }

}

# Get the RDM disks

Get-Cluster $clus | Get-VM | Get-View | %{

    $vm = $_

    $vm.Config.Hardware.Device | Where-Object {$_.gettype().Name -eq "VirtualDisk"} | %{

        if($_.Backing.PSObject.Properties['CompatibilityMode'] -and "physicalMode","virtualMode" -contains $_.Backing.CompatibilityMode){

            $disk = $_.Backing.LunUuid.Substring(10,32)

            $key = (Get-View $vm.Runtime.Host).config.Network.DnsConfig.Hostname + "-" + $disk

            $scsiTab[$key][1] = $vm.Name + "/" + $_.DeviceInfo.Label

        }

    }

}

$scsiTab.GetEnumerator() | Group-Object -Property {$_.Key.Split("-")[1]} | %{

    $lun = New-Object ("LunInfo" + $rndNum)

    $lun.ClusterName = $clus

    $_.Group | %{

        $esxName = $_.Key.Split("-")[0]

        $lun.$esxName = $_.Value[3]

        if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}

        if(!$lun.Vendor){$lun.Vendor = {(Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor}}

        if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}

        if(!$lun.SizeGB){$lun.SizeGB = [math]::Round($_.Value[2],0)}

        $lun.DSC = $_.Value[4]

    }

    $lun

} | Export-Excel -Path $csvName -AutoFilter -AutoSize -WorksheetName VM_Free_Disk_Info

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try replacing this line

if (!$lun.Vendor) {$lun.Vendor = {(Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor}}

with these lines

if (!$lun.Vendor) {

   $lun.Vendor = (Get-EsxCli -VMHost $esxImpl).storage.core.device.list($_.Value[0]).Vendor

}


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try replacing this line

if (!$lun.Vendor) {$lun.Vendor = {(Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor}}

with these lines

if (!$lun.Vendor) {

   $lun.Vendor = (Get-EsxCli -VMHost $esxImpl).storage.core.device.list($_.Value[0]).Vendor

}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much Smiley Happy

0 Kudos