7 Replies Latest reply on Oct 7, 2019 10:37 AM by ibrarsajid1

    Disabling paths to migrate all FC storage connections to specified port on HBA

    firestartah Master
    vExpertCommunity Warriors

      Hi

       

      Do any PowerCLI guru's know a way to run a script to disable all the paths to a specified FC hba card port? I need to route all my storage to 1 port on my HBA so as to enable me to remove one of my storage switches and doing it via VC is painfully slow

       

      Gregg

        • 1. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Does this work for you ?

           

          $tgtHBA = "vmhba1"
          Get-VMHost | Get-ScsiLun -LunType disk | where {$_.RuntimeName.Contains($tgtHBA)} | `
          Get-ScsiLunPath | Set-ScsiLunPath -Active:$false

           

          Note that this will disable all paths. If you want to keep 1 or more paths active, you will have to select another selection criteria.

          And that can be done via another where-clause

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 2. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
            firestartah Master
            Community WarriorsvExpert

            Hi Luc

             

            Thanks for the response. It does work but as you said disables all paths whereas i need all the paths going to one of the FC HBA ports disabled while the others still enabled to allow me to keep the hosts all running and change over switch by switch.

             

            For the second where clause what information would i need to put in?

             

            Gregg

            • 3. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
              firestartah Master
              vExpertCommunity Warriors

              The Get-Host portion wont accept anything and keeps bring up an "unexpected token" error in powergui. I've tried the -name and numerous other options but it keeps saying unexpected token

               

              Gregg

              • 4. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                The Get-VMHost error was most probably due to a <CR><LF> problem with the copy/paste of the code I did.

                I corrected that, give it another try.

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 5. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  I had a closer look and I suspect that the port WWN is the best way to select the paths that are connected to a specific port.

                  The script becomes something like this

                   

                  $tgtHBA = "vmhba1" 
                  $tgtPortWWN
                  = "5766023041194672011"
                  Get-VMHost
                  | Get-ScsiLun -LunType disk | where {$_.RuntimeName.Contains($tgtHBA)} | `
                  Get-ScsiLunPath | where {$_.Extensiondata.Transport.PortWorldWideName -eq $tgtPortWWN} | `
                  Set-ScsiLunPath
                  -Active:$false

                   

                  To get an overview of the hosts, their HBAs, the targets and the port WWNs, you can do

                   

                  foreach($esx in (Get-View -ViewType HostSystem -Property Name,Config.StorageDevice)){
                      foreach($hba in $esx.Config.StorageDevice.ScsiTopology.Adapter){
                          if($hba.Target){
                              $hba.Target | Select @{N="VMHost";E={$esx.Name}},
                                  @{N="HBA";E={($esx.Config.StorageDevice.HostBusAdapter | where {$_.Key -eq $hba.Adapter}).Device}},
                                  Target,
                                  @{N="Port WWN";E={$_.Transport.PortWorldWideName}}
                          }
                      }
                  }
                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
                    firestartah Master
                    vExpertCommunity Warriors

                    Thanks Luc that worked a charm!

                     

                    Gregg

                    • 7. Re: Disabling paths to migrate all FC storage connections to specified port on HBA
                      ibrarsajid1 Lurker

                      I've been scratching my head why when I'm targetting hba2 it works fine but when I target hba4, it doesn't work.. I've 4 ports, 2 on hba2 and 2 on hba4.. I can target both ports on hba2 but can't target the 2 ports on hba4. I need to return paths from each one of these and wondering why it doesn't work for hba4 when that exists.

                       

                      This works:

                       

                      $tgtHBA = "vmhba2"

                      $tgtPortWWN = "samplewwn:00"

                      $tgtNAA = "naa.samplenumberhere"

                      Get-VMHost | Get-ScsiLun -LunType disk | where {$_.RuntimeName.Contains($tgtHBA) -and $_.CanonicalName -eq $tgtNAA} | `

                      Get-ScsiLunPath | where {$_.SanID -eq $tgtPortWWN} | `

                      Set-ScsiLunPath -Active:$false

                       

                      This doesn't work:

                      $tgtHBA2 = "vmhba4"

                      $tgtPortWWN2 = "samplewwn:11"

                      $tgtNAA2 = "naa.samplenumberhere"

                      Get-VMHost | Get-ScsiLun -LunType disk | where {$_.RuntimeName.Contains($tgtHBA2) -and $_.CanonicalName -eq $tgtNAA2} | `

                      Get-ScsiLunPath | where {$_.SanID -eq $tgtPortWWN2} | `

                      Set-ScsiLunPath -Active:$false