script to check dead lun path

    
###########################################################################################
# Description:
# document output : DeadLunPath.csv
###########################################################################################

##################
# Add VI-toolkit #
##################
& {
$ErrorActionPreference = "silentlycontinue"
$vmwareSnap = get-pssnapin -name "VMware.VimAutomation.Core"
if (! $?)
{
 Add-PSsnapin VMware.VimAutomation.Core
 Initialize-VIToolkitEnvironment.ps1
}
}

##############################################################
# replace vcenter name by vcenter host name                  #
##############################################################
$vcserver = "Vcenter name"
connect-VIServer $vcserver
$filelocation1="c:\temp\DeadLunPath.csv"
$TranscriptFile = "c:\temp\logfile.log"
Start-Transcript -Path $TranscriptFile

function DeadLunPath
{
 Write-host "Processing"
 $report = @()
 $hosts = get-vmhost
 foreach ($unHost in ($hosts | where {$_.State -eq "Connected" -or $_.State -eq "Maintenance"}))
 {
  $deadluns = @()
  $esxPaths = Get-ScsiLun -vmhost $unHost | Get-ScsiLunPath
 
  foreach ($esxPath in $esxPaths)
  {
   if ($esxPath.state -eq "Dead")
   {
    $myObj = "" | Select VMHost, Lunpath, State
    $myObj.VMHost = $unHost
    $myObj.Lunpath = $esxlun.Lunpath
    $myObj.State = $esxlun.state
    $deadluns += $myObj
   }   
  }
 
  if(($deadluns | Measure-Object).count -gt 0)
  {
   $myObj = "" | Select "Host", "Dead path count"
   $myObj."Host" = $unHost.Name
   $myObj."Dead path count" = ($deadluns | Measure-Object).count
  
   $report += $myObj
  }
 }
 $report | sort "Host" | Export-CSV $filelocation1 -NoTypeInformation
}

DeadLunPath
##############################
# Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false
Stop-Transcript
#######################################################
# end of script #
#######################################################

Commentaires

Messages les plus consultés de ce blogue

La certification VMware VCP VMC est gratuite pour un temps limité

home lab

Nouveautés d’Azure VMware Solution