VMware Cloud Community
Virtualduty
Enthusiast
Enthusiast

Script to pull storage path information for specific esxi hosts.

Hello All,

I want to view the storage path status and count of each dead and active path for specific hosts. I've got below script , however I want to modify the script to add input file where I can specify the list of ESXi hosts which the script would query. Any input will be greatly appreciated,

&{foreach($esx in Get-VMHost){

    $esxcli = Get-EsxCli -VMHost $esx -V2

    foreach($adapter in $esxcli.storage.core.adapter.list.Invoke() | where{$_.Driver -match 'fc'}){

        $obj = [ordered]@{

            VMHost = $esx.Name

            Adapter = $adapter.HBAName

            Active = 0

            Standby = 0

            Dead = 0

        }

        $esxcli.storage.core.path.list.Invoke() | where{$_.Adapter -eq $adapter.HBAName} |

        Group-Object -Property State | %{

            $obj."$($_.Name)" = $_.Group.Count

        }

        New-Object PSObject -Property $obj

    }

}} | Export-Csv report.csv -NoTypeInformation -UseCulture

1 Reply
kwhornlcs
Enthusiast
Enthusiast

Start with a text file of the hosts you want like:

host1.local

host2.local

host3.local

Save the text file to something like targethosts.txt

Then change the first line of your script (the ForEach) to:

$hostlist = Get-Content targethosts.txt

ForEach ($esx in $hostlist){