LucD
Leadership
Leadership

I did a complete overhaul of the code.

Try it like this

$dcName = "MyDatacenter"
$clusterName = "MyCluster"

$list = Get-Datacenter -Name $dcName | %
 
$datacenter=$_
 
$datacenter | Get-Cluster -Name $clusterName | %{
   
$cluster = $_
   
Get-VMhost -Location $cluster | Get-VMHostHBA -Type FibreChannel | where {$_.Status -eq "online"} |
     
Select @{N="Datacenter";E={$datacenter}},
       
@{N="Cluster";E={$cluster}},
       
@{N="VMHost";E={$_.VMHost.Name}},
       
Device,Status,
       
@{N="WWN";E={((("{0:X}"-f $_.PortWorldWideName).ToLower()) -replace "(\w{2})",'$1:').TrimEnd(':')}}
    }
}

#Output CSV to current directory.
$list | export-csv -NoTypeInformation C:\output.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos