Author Posts

February 25, 2016 at 8:44 pm

Dear community
I need your help ,I have the below script that pulls out the report Checking for “Dead” paths on HBAs with PowerCLI . I was able to pull out the details but I have problem exporting them in to csv . when I export to csv the datastore property is showing like system.object[] . could some one please help me. Thanks.

Name : test.esx.com
Device : vmhba8
Cluster : testcluster.
ActiveP : 11
DeadP : 0
StandbyP : 11
Datastore : {DataStore_L1, DataStore_L2, DataStore_L3, DataStore_L4...}

$VMHosts = get-cluster | Get-VMHost | ? { $_.ConnectionState -eq “Connected” } | Sort-Object -Property Name
$allresults= @()
$datastore = @()
foreach ($VMHost in $VMHosts) {
 write-host “Working on host $VMHost”
[ARRAY]$HBAs = $VMHost | Get-VMHostHba -Type “FibreChannel”
$datastore = Get-Datastore -VMHost $VMHost

foreach ($HBA in $HBAs) {
 $results = “” | select Name, Device, Cluster, ActiveP, DeadP, StandbyP , Datastore
 $pathState = $HBA | Get-ScsiLun | ? { $_.Vendor -match “EMC”} | Get-ScsiLunPath | Group-Object -Property state
 $results.Name = $VMHost.Name
 $results.Device = $HBA.Device
 $results.Cluster = $VMHost.Parent
 $results.ActiveP = [INT]($pathState | ? { $_.Name -eq “Active”}).Count
 $results.DeadP = [INT]($pathState | ? { $_.Name -eq “Dead”}).Count
 $results.StandbyP = [INT]($pathState | ? { $_.Name -eq “Standby”}).Count
 $results.Datastore = [ARRAY]$datastore.name 
 $allresults += $results
 }

}

# Display the results in Gridview
 $allresults | ft -AutoSize
 # Or export to a CSV
  $allresults | export-csv -Path C:\Temp\path.csv 
  C:\Temp\path.csv
disconnect-viserver -confirm:$false

February 26, 2016 at 11:18 am

Pls some one can help me here . Thanks

February 26, 2016 at 12:12 pm

System.Object[] with Export-Csv, huh?

You can read Boe Prox's post about that here: http://learn-powershell.net/2014/01/24/avoiding-system-object-or-similar-output-when-using-export-csv/, and see one of the solutions implemented in a function I wrote here: http://tommymaynard.com/script-sharing-find-dns-servers-being-used-by-dhcp-scopes-2015/.

This may be all you need:

 $results.Datastore = ([ARRAY]$datastore.name) -join ','

February 26, 2016 at 7:43 pm

Hi tommy
This is exactly what i need 😊.. Thanks for taking ur time to answer my query..ps community rocks 😊😊