Need Help CSV export

Welcome Forums General PowerShell Q&A Need Help CSV export

Viewing 3 reply threads
  • Author
    Posts
    • #35721
      Participant
      Topics: 15
      Replies: 24
      Points: 4
      Rank: Member

      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
      
    • #35763
      Participant
      Topics: 15
      Replies: 24
      Points: 4
      Rank: Member

      Pls some one can help me here . Thanks

    • #35775
      Participant
      Topics: 2
      Replies: 95
      Points: 893
      Rank: Major Contributor

      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 ','
    • #35790
      Participant
      Topics: 15
      Replies: 24
      Points: 4
      Rank: Member

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

Viewing 3 reply threads
  • The topic ‘Need Help CSV export’ is closed to new replies.