PowerCLI

 View Only
  • 1.  Powershell script to see paths

    Posted Feb 01, 2013 08:16 AM

    Hi,

    Need a simple script to check how many paths are available from each vhba. Also need it to determine if there are any dead paths reported.

    Output :

    vmhba1 :

    Targets :2

    Devices:10

    Paths:9

    Dead Path :

    vmhba1:c0:t0:l0 Target Lun Status

    vmhba2:

    Targets :2

    Devices:10

    Paths:10

    Thx



  • 2.  RE: Powershell script to see paths

    Posted Feb 01, 2013 10:04 AM

    Got something related from Luc script at http://communities.vmware.com/message/1766761 but what i want is:

    Number of paths from the givern vmhba

    Dead path and/or missing path with the details.

    Any suggestions?



  • 3.  RE: Powershell script to see paths

    Posted Feb 01, 2013 10:26 AM

    How would you determine dead paths ?



  • 4.  RE: Powershell script to see paths

    Posted Feb 04, 2013 05:28 AM

    Hi Luc,

    I meant something like we can see on the GUI or manually from the ESXi console. If that's not possible can we just determine the number of paths?



  • 5.  RE: Powershell script to see paths
    Best Answer

    Posted Feb 04, 2013 07:51 AM

    Would something like this do ?

    foreach($esx in Get-VMHost){
      foreach($hba in (Get-VMHostHba -VMHost $esx -Type "FibreChannel")){
        $target = $hba.VMhost.ExtensionData.Config.StorageDevice.ScsiTopology.Adapter | 
          where {$_.Adapter -eq $hba.Key} | %{$_.Target}
        $luns = Get-ScsiLun -Hba $hba -LunType "disk" -ErrorAction SilentlyCOntinue | Measure-Object | Select -ExpandProperty Count
        $nrPaths = $target | %{$_.Lun.Count} | Measure-Object -Sum | select -ExpandProperty Sum
       
    $hba | Select @{N="VMHost";E={$esx.Name}},@{N="HBA";E={$hba.Name}},
        @{N="Target#";E={if($target -eq $null){0}else{@($target).Count}}},@{N="Device#";E={$luns}},@{N="Path#";E={$nrPaths}}   } }


  • 6.  RE: Powershell script to see paths

    Posted Feb 04, 2013 10:22 AM

    Perfect.thanks!



  • 7.  RE: Powershell script to see paths

    Posted Aug 14, 2013 12:28 PM

    Hi

    Just what I was looking for too, how could you export this to csv please?



  • 8.  RE: Powershell script to see paths

    Posted Aug 14, 2013 12:53 PM

    A ForEach loop doesn't place objects on the pipeline, so you'll have to use a trick.

    Place the complete script in a call block, and then you can do the export.

    It would look something like this

    & {

    # The original script

    }
    | ExExport-Csv C:\report.csv -NoTypeInformation -UseCulture


  • 9.  RE: Powershell script to see paths

    Posted Aug 14, 2013 12:58 PM

    Stunning, that has just saved me a huge amount of OAT testing time.

    Many thanks