title: Powershell/Excel - Parsing/Splitting and exporting to excel
body: <p>I am trying to extract specific pieces of data from a text file and write them to an excel workbook.  Originally I was able to extract the data to excel, but I need only a part of certain cells, and so was modifying the data in excel, with only a certain amount of success.  I'm trying to single out the specific data in powershell before exporting it, but have hit a brick wall.
  This is what I have so far:</p>
  
  <pre><code>#User input relevant folder location
  $i = read-host "Please enter Folder Location: "
  
  #import data
  Select-String -pattern "     CISCO1941/K9     " -path "$i\*-Live.txt" | Export-CSV $i\InventoryRAW_Router.csv
  
  #parse data
  $RouterHNM = Import-CSV $i\InventoryRAW_Router.csv | select-object Line 
  $a = -split $RouterHNM
  $b = $a -join ","
  $b
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code>  @{Line=*0,CISCO1941/K9,FCxxxxxxxYR},@{Line=*0,CISCO1941/K9,FCxxxxxxxCF},@{Line=*0,CISCO1941/K9,FCxxxxxxxBN}
  </code></pre>
  
  <p>To be honest I don't know what to do next, when I try to export the data using:
      | Export-CSV $i\b.txt"<br>
  I get:
      #TYPE System.String
      "Length"
      "107"</p>
  
  <p>and I can't seem to split the data.</p>
  
  <p>Any help would be greatly appreciated!!
  Thanks</p>
  
  <p>further info:
  sample text file data is imported from:</p>
  
  <pre><code>router01-Live#sh ver
  Cisco IOS Software, xxx, RELEASE SOFTWARE (fc1)
  Technical Support: http://www.cisco.com/techsupport
  Copyright (c) 1986-2012 by Cisco Systems, Inc.
  Compiled Tue 20-Mar-12 17:58 by prod_rel_team
  
  ROM: System Bootstrap, Version xxx
  
  router01 uptime is 1 minute
  System returned to ROM by power-on
  System restarted at xxx
  System image file is "flash0:xxx.bin"
  Last reload type: Normal Reload
  
  
  This product contains cryptographic features and is subject to United
  States and local country laws governing import, export, transfer and
  use. Delivery of Cisco cryptographic products does not imply
  third-party authority to import, export, distribute or use encryption.
  Importers, exporters, distributors and users are responsible for
  compliance with U.S. and local country laws. By using this product you
  agree to comply with applicable laws and regulations. If you are unable
  to comply with U.S. and local laws, return this product immediately.
  
  A summary of U.S. laws governing Cisco cryptographic products may be found at:
  http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
  
  If you require further assistance please contact us by sending email to
  export@cisco.com.
  
  Cisco CISCO1941/K9 (revision 1.0) with 491520K/32768K bytes of memory.
  Processor board ID xxxx
  
  DRAM configuration is 64 bits wide with parity disabled.
  255K bytes of non-volatile configuration memory.
  250880K bytes of ATA System CompactFlash 0 (Read/Write)
  
  
  License Info:
  
  License UDI:
  
  -------------------------------------------------
  Device#   PID                   SN
  -------------------------------------------------
  *0        CISCO1941/K9          FCxxxxxxxYR
  
  
  
  Technology Package License Information for Module:'c1900'
  
  -----------------------------------------------------------------
  Technology    Technology-package           Technology-package
            Current       Type           Next reboot
  ------------------------------------------------------------------
  ipbase        ipbasek9      Permanent      ipbasek9
  security      None          None           None
  data          None          None           None
  
  Configuration register is 0x2102
  </code></pre>
  
  <p>and the excel output should be a simple list of hostname, serial number and model, the returned data shown:
      @{Line=*0,CISCO1941/K9,FCxxxxxxxYR},@{Line=*0,CISCO1941/K9,FCxxxxxxxCF},@{Line=*0,CISCO1941/K9,FCxxxxxxxBN}</p>
  
  <p>contains the model &amp; hostname from 3 different text files, and so I want to extract the 2nd and 3rd pieces of info from each array into excel.</p>