How to: Load multiple lines into array

Welcome Forums General PowerShell Q&A How to: Load multiple lines into array

Viewing 6 reply threads
  • Author
    Posts
    • #245337
      Participant
      Topics: 3
      Replies: 6
      Points: 51
      Rank: Member

      Hello,

      I need to build a simple script to automate reporting in storage. I have the following:

      This works, but the naviseccli command returns multiple lines. For example:

      LUN_id= 2
      Pool Name: MyPool
      Pool ID: 2
      Consumed Capacity (Blocks): 176033627136
      Consumed Capacity (GBs): 83939.375
      Available Capacity (Blocks): 58651610112
      Available Capacity (GBs): 27967.267

      I need to format the Consumed GBs and Available GBs into an .csv file.

      Any suggestions greatly appreciated.

    • #245388
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Search for “Powershell naviseccli”. Command line output needs to be parsed into PSObject to use Export-CSV. Below is a report (HTML) and the second is a wrapper function that does some parsing:

      Automating Health Check on EMC VNX
      http://blog.superautomation.co.uk/2016/03/simple-wrapper-function-for-naviseccli.html

    • #247086
      Participant
      Topics: 3
      Replies: 6
      Points: 51
      Rank: Member

      Hello Rob,

      First of all, thank you for your suggestion. I was able to get it working on my array and expanded on it by calculating TB’s and exporting to .csv.

      One thing that still eludes me is adding a subtotal line for each column on the .csv.

      Below is what I have so far. Any help greatly appreciated.

    • #247243
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Cannot test, but this is a little cleaner way to use the last item rather than the first item to create the object and use switch rather than If\Else, but if the current function is working, you can ignore the update:

      One thing that still eludes me is adding a subtotal line for each column on the .csv.

      There isn’t really a subtotal line per se, but a separate property. Get the data and then use Calculated Properties to do the rounding and calculations. Here is a WMI query to get the memory which is returned in bytes and then using an expression we get MB and GB:

    • #247324
      Participant
      Topics: 3
      Replies: 6
      Points: 51
      Rank: Member

      After I posted I realized the server where naviseccli is installed has is Windows Server 2008 with PowerShell 2.0. I then launched the script from a different server that has PS v5.0 and it is now working.

      To get the subtotals, I’m thinking to import the csv, calculate the subtotals then export to a second .csv using something like:

      $total = Import-Csv "c:\temp\test1.csv" | Measure-Object 'RawTB' -Sum
      'Total {0:n2}' -f $total.Sum 

       

       

       

       

      I like this format much better. However, when I export to csv

      $results = Get-PoolDetails "VNX5800 " 10.10.10.10
      $results | Export-Csv 'c:\temp\test1.csv' -NoTypeInfo

      I’m getting the following in c:\temp\test1.csv:

      IsReadOnly","IsFixedSize","IsSynchronized","Keys","Values","SyncRoot","Count"
      "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","6"
      "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","6"
      "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","6"
      "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","6"
      "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","6"

      • This reply was modified 1 month, 2 weeks ago by obijuan.
    • #247327
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,782
      Helping Hand
      Rank: Community Hero

      Are you using PowerShell version 2 ? Because type casting hastable to PSCsutomObject to create a custom object doesn’t work in v2, your csv looks like a hashtable exported to csv format. Modify the object creation part in the above code like below.

      • This reply was modified 1 month, 2 weeks ago by kvprasoon. Reason: code correction
    • #247336
      Participant
      Topics: 3
      Replies: 6
      Points: 51
      Rank: Member

      That was exactly my problem. Works in 5.0,

      Thanks.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.