title: Generically Transpose PowerShell Array Rows into Columns
body: <p>There are <a href="https://stackoverflow.com/questions/25651685/convert-table-of-row-based-records-to-column-based-records-csv">quite</a> a <a href="https://stackoverflow.com/questions/1736613/how-to-transpose-data-in-powershell">few</a> <a href="https://stackoverflow.com/questions/33906500/powershell-csv-row-column-transpose-and-manipulation">posts</a> on SO that address PowerShell transposition. However, most of the code is specific to the use case or addresses data being gathered from a text/CSV file and does me no good. I'd like to see a solution that can do this work without such specifics and works with arrays directly in PS.</p>
  
  <p>Example data:</p>
  
  <pre><code>Customer Name:    SomeCompany
  Abbreviation:    SC
  Company Contact:    Some Person
  Address:    123 Anywhere St.
  ClientID:    XXXX
  </code></pre>
  
  <p>This data is much more complicated, but I can work with it using other methods if I can just get the rows and columns to cooperate. The array things that "Name:" and "SomeCompany" are column headers. This is a byproduct of how the data is gathered and cannot be changed. I'm importing the data from an excel spreadsheet with <a href="http://ramblingcookiemonster.github.io/PSExcel-Intro/" rel="nofollow noreferrer">PSExcel</a> and the spreadsheet format is not changeable.</p>
  
  <p>Desired output:</p>
  
  <pre><code>Customer Name:, Abbreviation:, Company Contact:, Address:, ClientID:
  SomeCompany, SC, Some Person, 123 Anywhere St., XXXX
  </code></pre>
  
  <p>Example of things I've tried:</p>
  
  <pre><code>$CustInfo = Import-XLSX -Path "SomePath" -Sheet "SomeSheet" -RowStart 3 -ColumnStart 2
  $b = @()
  foreach ($Property in $CustInfo.Property | Select -Unique) {
      $Props = [ordered]@{ Property = $Property }
      foreach ($item in $CustInfo."Customer Name:" | Select -Unique){ 
          $Value = ($CustInfo.where({ $_."Customer Name:" -eq $item -and 
                      $_.Property -eq $Property })).Value
          $Props += @{ $item = $Value }
      }
      $b += New-Object -TypeName PSObject -Property $Props
  }
  </code></pre>
  
  <p>This does not work because of the "other" data I mentioned. There are many other sections in this particular workbook so the "Select -Unique" fails without error and the output is blank. If I could limit the input to only select the rows/columns I needed, this might have a shot. It appears that while there is a "RowStart" and "ColumnStart" to Import-XLSX, there are no properties for stopping either one.</p>
  
  <p>I've tried methods from the above linked SO questions, but as I said, they are either too specific to the question's data or apply to importing CSV files and not working with arrays.</p>