9 Replies Latest reply on Aug 19, 2013 4:14 PM by ssbkang

    SAN Information Needed

    jessem Enthusiast

      Hey everyone,

       

      I need help outputting the following information in a csv.

       

      Hostname,

      Datastore Name

      LUN/Canonical Name

      Path State (Active/Dead)

        • 1. Re: SAN Information Needed
          ssbkang Hot Shot
          vExpert

          Hi,

           

          The following script should do, modify the bold and italic line to change the output path:

           

          $output = foreach ($esxi in Get-VMHost | Sort Name)

          {

              $esxcli = Get-EsxCli -VMHost $esxi

              $datastore_info = $esxi.ExtensionData.Config.FileSystemVolume.MountInfo | %{$_.Volume} | Where-Object { if ($_.Name) { $_ } }

              foreach ($datastore in $datastore_info | Sort Name)

              {

                  $adapter_information = $esxcli.storage.core.path.list() | Where-Object {$_.Device -match ($datastore.Extent | %{$_.DiskName})}      

                  $datastore | Select-Object @{N="ESXi";E={$esxi.Name}}, @{N="Datastore";E={$datastore.Name}}, @{N="Canonical Name";E={$datastore.Extent | %{$_.DiskName}}}, @{N="RunTimeName";E={[string]::Join(",", ($adapter_information | %{$_.RunTimeName}))}}, @{N="State";E={[string]::Join(",", ($adapter_information | %{$_.State}))}}

              }

          }

          $output | Export-Csv "C:\Location\output.csv"

           

          Sample Output:

           

          ESXi           : abcd.test.com                                                                                                                                                                 

          Datastore      : test_volume                                                                                                                                                                           

          Canonical Name : naa.600xxxxxxxxxxxxxxxxxx                                                                                                                                                       

          RunTimeName    : vmhba1:C0:T0:L0,vmhba1:C0:T0:L1                                                                                                                                                            

          State          : active,active

           

          Hope this helps,

          Steven.

          1 person found this helpful
          • 2. Re: SAN Information Needed
            LucD Guru
            Community WarriorsvExpertUser Moderators

            Nice script.

            If I might suggest the following small change.

            This version will only show VMFS volumes and take into account that there might be multi-extent VMFS datastores.

             

            $output = foreach ($esxi in Get-VMHost | Sort Name)
            {
             
            $esxcli = Get-EsxCli -VMHost $esxi
             
            $datastore_info = $esxi.ExtensionData.Config.FileSystemVolume.MountInfo | %{$_.Volume} | Where-Object { if ($_.Name) { $_ } }
             
            foreach ($datastore in $datastore_info | Sort Name)
              {
               
            $esxcli.storage.vmfs.extent.list() | where {$_.VolumeName -eq $datastore.Name} | %{
                 
            $adapter_information = $esxcli.storage.core.path.list($_.DeviceName)
                 
            $datastore | Select-Object @{N="ESXi";E={$esxi.Name}},
                 
            @{N="Datastore";E={$datastore.Name}},
                 
            @{N="Canonical Name";E={$datastore.Extent | %{$_.DiskName}}},
                 
            @{N="RunTimeName";E={[string]::Join(",", ($adapter_information | %{$_.RunTimeName}))}},
                 
            @{N="State";E={[string]::Join(",", ($adapter_information | %{$_.State}))}}
                }
              }
            }
            $output | Export-Csv "C:\output.csv" -UseCulture
            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
            1 person found this helpful
            • 3. Re: SAN Information Needed
              ssbkang Hot Shot
              vExpert

              Hi LucD,

               

              Thanks for the suggestion, that looks great

               

              Regards,

              Steven.

              • 4. Re: SAN Information Needed
                jessem Enthusiast

                Thanks guys.  One thing I forget to mention.  Where in the script can I fit the name of the Cluster I want it to target? 

                • 5. Re: SAN Information Needed
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  At the top of the ForEach loop, inside the code block you can insert a line like this

                  $cluster = Get-Cluster -VMHost $esxi

                  Then add a calculated property on the Select cmdlet

                  @(N="Cluster";E={$cluster.Name}}

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: SAN Information Needed
                    jessem Enthusiast

                    Hello, that will work.  However, I guess maybe I'm confusing things.  Were in the code, can I actually specify the actual name of the cluster myself?

                     

                    get-cluster "os 01"

                     

                     

                    and then have that output to the csv

                    • 7. Re: SAN Information Needed
                      LucD Guru
                      Community WarriorsUser ModeratorsvExpert

                      Change the 1st line

                       

                      $output = foreach ($esxi in Get-VMHost | Sort Name)


                      into


                      $output = foreach ($esxi in GetCluster -Name "os 01" | Get-VMHost | Sort Name)

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: SAN Information Needed
                        jessem Enthusiast

                        Thanks, that didn't work at first, simple correct...appreciate the help like always!

                         

                        $output = foreach ($esxi in Get-Cluster -Name "os 01" | Get-VMHost | Sort Name)

                        • 9. Re: SAN Information Needed
                          ssbkang Hot Shot
                          vExpert

                          Thanks for replying LucD