0

For example, I have csv file and then imported to PowerShell:

$animal = Import-Csv “animal.csv”
$animal

Output is:

Animal
------
Bird
cat
dog

I would like to convert to array value, i.e. I would like to put these "bird","cat","dog" in array, basically like this:

$newanimals = "Bird","Cat","Dog"

How can I do that?

2 Answers 2

3
$newanimals = Import-Csv -Path "animal.csv" | Select -ExpandProperty Animal
Sign up to request clarification or add additional context in comments.

Comments

1

Quick and dirty:

Import-Csv ".\animal.csv" | Foreach-Object {$arrayOfAnimals += @($_.Animal)}
Write-Host $arrayOfAnimals #Bird cat dog
$arrayOfAnimals[1] #cat

Comments

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.