0

I am using the .net web object to retrieve a text file which is comma delimited.

The variable comes back as a single array as if I had used Get-Content to load it from disk. I use a foreach loop to insert a comma between the date and the time values in the array so I have 3 columns.

I then save the array to disk using Set-Content and then reload it using Import-CSV to get a Multi Dimensional array that I can then use with select.

Is there a way of converting the array type without saving it to disk and reloading it?

Thank you

1
  • 2
    Can you post your code and some sample data? Commented Mar 28, 2014 at 15:34

1 Answer 1

1

Pipe the text into ConvertFrom-Csv. It works on both an array of strings(like Get-Content returns), and on multiline strings.

Array of strings:

$res = @"
Name,Age
Frode,22
Jesus,2014
"@ -split "`r`n"

$res | ConvertFrom-Csv

Name  Age 
----  --- 
Frode 22  
Jesus 2014

One big multiline string:

$res = @"
Name,Age
Frode,22
Jesus,2014
"@

$res | ConvertFrom-Csv

Name  Age 
----  --- 
Frode 22  
Jesus 2014
Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome :) If you consider this to be the correct answer for your question, please mark it as so by clicking on the checkmark next to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.