PowerCLI

 View Only
  • 1.  Vendor Name and LUN number

    Posted Mar 19, 2025 04:38 AM

    Hi,

    How can I get the Vendor Name and LUN number for the below script, please help!!

    function Get-FreeScsiLun {
    param (
    [parameter(ValueFromPipeline = $true,Position=1)]
    [ValidateNotNullOrEmpty()]
    [VMware.VimAutomation.Client20.VMHostImpl]
    $VMHost
    )
    process{
    $storMgr = Get-View $VMHost.ExtensionData.ConfigManager.DatastoreSystem
    $storMgr.QueryAvailableDisksForVmfs($null) | %{
    New-Object PSObject -Property @{
    VMHost = $VMHost.Name
    CanonicalName = $_.CanonicalName
    Uuid = $_.Uuid
    CapacityGB = [Math]::Round($_.Capacity.Block * $_.Capacity.BlockSize / 1GB,2)
    }
    }
    }
    }

    $esx = Get-VMHost -Name "myesx"
    Get-FreeScsiLun -VMHost $esx | Select VMHost, CanonicalName, CapacityGB, Uuid | ft -auto



  • 2.  RE: Vendor Name and LUN number

    Posted Mar 24, 2025 02:43 PM

    Hi All,

    Anyone, please help!!




  • 3.  RE: Vendor Name and LUN number
    Best Answer

    Posted Apr 01, 2025 01:40 AM
    Edited by ganapa2000 Apr 16, 2025 02:58 AM

    $vCenter = Connect-VIServer -Server $vCenterName -Credential $Credential

    $DataStoreViews = Get-View -ViewType Datastore -Server $vCenter -Property Name, Host, Summary, Info | Sort Name
    $VMHostViews = Get-View -ViewType HostSystem -Server $vCenter -Property Name, Runtime, Summary, 'Config.StorageDevice'
    $DataStoreSummary = [System.Collections.ArrayList]@()
    ForEach($DataStoreView in $DataStoreViews){
        IF($DataStoreView.Info.vmfs -ne $Null){$CanonicalName = $DataStoreView.Info.vmfs.Extent[0].DiskName}Else{$CanonicalName = $Null}
        $LUN = $Null
        IF($DataStoreView.Info.vmfs.Extent){
            $VMHostView = $VMHostViews | ?{$DataStoreView.Host.Key -Contains $_.MoRef} | ?{$_.Client.ServiceURL.Split('/')[2] -eq $DataStoreView.Client.ServiceURL.Split('/')[2]} | ?{$_.Runtime.PowerState -eq "poweredOn"} | ?{($_.Runtime.ConnectionState -eq "connected") -Or ($_.Runtime.ConnectionState -eq "maintenance")} | Select -First 1
            IF($CanonicalName){$LUN = $VMHostView.Config.StorageDevice.ScsiLun | ?{$_.CanonicalName -eq $DataStoreView.Info.vmfs.Extent[0].DiskName}}
        }
        $TmpData = $Null; 
        $TmpData = [PSCustomObject]@{
            Name = $DataStoreView.Name
            Id = $DataStoreView.MoRef
            Type = $DataStoreView.Summary.Type
            VMHostIds = $DataStoreView.Host.Key
            CapacityGB =  $([Math]::Round(($DataStoreView.Summary.Capacity/([MATH]::pow(1024,3))),2))
            CanonicalName = $CanonicalName
            DataStore_Uuid = $DataStoreView.Info.vmfs.Uuid
            LUN_Uuid = $($LUN.Uuid)
            Vendor = $($LUN.Vendor)
            LUN_Number = $(IF($LUN){(($VMHostView.Config.StorageDevice.MultipathInfo.lun | ?{$_.Id -eq $LUN.Uuid}).Path.Name | Select -First 1).Split(':')[-1]})
            vCenter = $DataStoreView.Client.ServiceURL.Split('/')[2]
        }
        IF($TmpData){$DataStoreSummary.Add($TmpData) | Out-Null}
    }

    $DataStoreSummary