Check-MultipathInfo.ps1

Version 2

    This script generates info about your datastores based on the Hosts you provide.

    Plus, i've created a function to get the Datastore Names by naa id.

     

     

    <#
    ==================================================================
    Author(s):           Guilherme Alves Stela <guistela@br.ibm.com>
    Date:                25-03-2014
    ==================================================================
    Disclaimer: This script is written as best effort and provides no
    warranty expressed or implied. Please contact the author(s) if you
    have questions about this script before running or modifying.
    ==================================================================
    #>
    Connect-VIServer "myvcenter"
    $cluster = Get-cluster
    $vmhosts = $cluster|Get-VMHost
    $allOut = @()
    foreach($Vmhost in $vmhosts){
          Write-host "Seeing host $Vmhost"
          $Vmhost.ExtensionData.Config.StorageDevice.PlugStoreTopology.Path|%{
                $path = $_
                        $output = "" | select Vmhost,Adapter,WWN,LunNumber,Target,naa,DatastoreName
                        $Adapter = (($path.Adapter).split("-"))[2]
                        $output.Vmhost = $vmhost.Name
                        $output.Adapter = $Adapter
                        $output.LunNumber = $path.LunNumber
                        $mypath = $path.Name
                        $output.WWN = $mypath.split("-")[0]
                        $output.Target = $mypath.split("-")[1]
                        $output.naa = $mypath.split("-")[2]
                        $allOut += $output
                      Write-host "$Vmhost: Path: $mypath"
                   }#end Paths loop
    }#end vmhosts loop
    ##############################################
    $datastores =@()
    $vmhosts | Get-Datastore | %{$datast = $_
        $datast.ExtensionData.Info.Vmfs.Extent | %{
     
            $tempInfo = "" | select naa,DatastoreName
            $tempInfo.naa = $_.DiskName
            $tempInfo.DatastoreName = $datast.Name
            $datastores += $tempInfo       
        }
    }
    $allOut | %{
        $itemOut = $_
             $datastores |%{
                if($_.naa -eq $itemOut.naa){
                    $itemOut.DatastoreName = $_.DatastoreName
                }
             }      
    }
    ################################################
    $allOut |Export-csv -Path "C:\temp\mymultipathinfos.csv" -NoTypeInformation -useculture


    ####################################
    #function Get-DatastorebyNAA{ 
    #param ($paramhost,$naa)
      #$paramhost| Get-datastore | %{
      #$datast = $_
        #$_.ExtensionData.Info.Vmfs.Extent | %{
           #if( $_.Diskname -eq $naa){
                #$tempInfo = "" | select naa,DatastoreName
                #$tempInfo.naa = $_.DiskName
                #$tempInfo.DatastoreName = $datast.Name
                #$ALLINFO += $tempInfo         
            #}
        #}
      #}
    #return $tempInfo
    #}
    ###################################