PowerCLI

 View Only
  • 1.  Unable to get vendor details

    Posted Mar 02, 2020 01:08 PM

    Hi,

    I am unable to get the vendor details from the script, as I am getting blank and there is no error.

    Please help.



  • 2.  RE: Unable to get vendor details
    Best Answer

    Posted Mar 02, 2020 01:30 PM

    That code seems to come from my LUN Report – Datastore, RDM And Node Visibility post :smileygrin:

    Try like this

    Get-Cluster -PipelineVariable clus |

    ForEach-Object -Process {

        $rndNum = Get-Random -Maximum 99999


        $LunInfoDef = @"

        public string ClusterName;

        public string Vendor;

        public string CanonicalName;

        public string UsedBy;

        public string SizeGB;

        public string DSC; 

    "@

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


        $esxServers = $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

            $version = [Version]$esxImpl.Version

            if ($version.Major -eq 6 -and $version.Minor -eq 0)

            {

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

                    $key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.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, "", $_.Vendor

                }

            }

            Else

            {

                $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, "", $_.Vendor

                    }

                }

            }


            # 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

        $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.UsedBy) { $lun.UsedBy = $_.Value[1] }

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

                if (!$lun.Vendor) {$lun.Vendor = $_.Value[5]}

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

            }

            $lun

        }

    }



  • 3.  RE: Unable to get vendor details

    Posted Mar 03, 2020 04:59 AM

    That worked. Thank you very much LucD. :smileyhappy: