2 Replies Latest reply on Oct 30, 2017 5:05 PM by jooshilaig

    Get host Lun and device info

    antoniogemelli Enthusiast

      Hello,

      I have this script where I can get a lot of information's and I would like to add host (to be easy to identify) for each row, is possible?

       

      Adapter

      AdapterIdentifier

      AdapterTransportDetails

      ChannelDevice

      DeviceDisplayName

      LUN

      MaximumIOSize

      Plugin

      RuntimeName

      State

      Target

      TargetIdentifier

      TargetTransportDetails

      Transport

      UID

      Host?

       

      &{Get-VMhost | %{

       

       

               $esxcli = Get-esxcli -VMHost $_

       

       

               $esxcli.storage.core.path.list()

       

       

          }} | Export-Csv -path C:\Users\gemela\Desktop\SANLUN.csv

        • 1. Re: Get host Lun and device info
          mattboren Master
          vExpert

          Hello, -

           

          You can include the VMHost as a property of each object by adding a new calculated property to the output.  Like:

           

          & {Get-VMHost -PipelineVariable oThisVMHost | Foreach-Object {

              $esxcli = Get-EsxCli -VMHost $_

              $esxcli.storage.core.path.list() | Select-Object -Property *, @{Name="VMHost"; e={$oThisVMHost}}

          }} | Export-Csv -NoTypeInformation -Path C:\Users\gemela\Desktop\SANLUN.csv

           

          How does that do for you?

          • 2. Re: Get host Lun and device info
            jooshilaig Novice

            Try this script , it will give you an CSV output

             

            Header 1

            $Usr="root"

            $pwd='password'

            $CSVFile = ".\HostList.csv"

            $filelocation=".\MPath.csv"

            $hosts=Import-CSV $CSVFile

             

            foreach($singleViserver in $hosts)

            {

            $esxiserver=$singleViserver.name

            Connect-VIServer $singleViserver.name -User $Usr -password $pwd | Out-Null

            Write-Host "Getting the Multipath for Host $esxiserver......." -ForegroundColor Yellow

            $esxcli = get-vmhost $singleViserver.name | Get-EsxCli

            $esxcli.storage.core.path.list() |select @{N="VMHost";E={$ESXCLI.VMHost}},Adapter,AdapterIdentifier,AdapterTransportDetails,Channel,Device,DeviceDisplayName,LUN,Plugin,RuntimeName,State,Target,TargetIdentifier,TargetTransportDetails,Transport,UID|Export-Csv -Append $filelocation -Delimiter ","

             

            }