VMware Cloud Community
VCPAJAY
Contributor
Contributor

powerc cli script to export hostname,storage dead path,status

need a powerc cli script to export hostname,storage dead path,status  for a one data center ( or else all hhba info)

3 Replies
julienvarela
Commander
Commander

Hi,

Can you check this script :

#Get list of ESXi Hosts

$esxihosts = Get-VMHost

$i=0

$data = ForEach ($esxi in $esxihosts) {

  $i++

  Write-Progress -Activity "Scanning hosts" -Status ("Host: {0}" -f $esxi.Name) -PercentComplete ($i/$esxihosts.count*100) -Id 0

  $hbas = $esxi | Get-VMHostHba

  $j=0

  ForEach ($hba in $hbas) {

  $j++

  Write-Progress -Activity "Scanning HBAs" -Status ("HBA: {0}" -f $hba.Device) -PercentComplete ($j/$hbas.count*100) -Id 1

  $scsiluns = $hba | Get-ScsiLun

  $k=0

  ForEach ($scsilun in $scsiluns) {

  $k++

  Write-Progress -Activity "Scanning Luns" -Status ("Lun: {0}" -f $scsilun.CanonicalName) -PercentComplete ($k/$scsiluns.count*100) -Id 2

  $scsipaths = $scsilun | Get-Scsilunpath

  $l=0

  ForEach ($scsipath in $scsipaths) {

  $l++

  Write-Progress -Activity "Scanning Paths" -Status ("Path: {0}" -f $scsipath.Name) -PercentComplete ($l/$scsipaths.count*100) -Id 3

  New-Object PSObject -Property @{

  Host = $esxi.name

  HBAName = $scsilun.RuntimeName

  PathSelectionPolicy = $scsilun.MultiPathPolicy

  Status = $scsipath.state

  Source = "{0}" -f ((("{0:x}" -f $hba.PortWorldWideName) -split '([a-f0-9]{2})' | where {$_}) -Join ":")

  Target = $scsipath.SanId

  LUN = (($scsilun.RunTimeName -Split "L")[1] -as [Int])

  Path = $scsipath.LunPath

  }

  }

  }

  }

}

$data | Export-Csv -NoTypeInformation 'ESXiStorageInfo.csv'

Regards,

Julien

Regards, J.Varela http://vthink.fr
VCPAJAY
Contributor
Contributor

thanks Julien!

0 Kudos
julienvarela
Commander
Commander

hi,

don"t forget to mark as helpfull and answered.

Thank you,

Regards,

julien

Regards, J.Varela http://vthink.fr
0 Kudos