Convert .csv data to object

Hey guys,

I managed in the past to use .csv data as object with the import-csv cmdlet

Lately I tried to use the same cmdlet with csv data that looks like this

Device,Deployment

Device1,Deployment1

Device1,Deployment2

Device2,Deployment1

etc

 

And I’m not able to retrieve the data using like :

$csvfile = Import-Csv “PathtoCsv”

foreach ($line in $csvfile)

{

$device = $line.Device

$deployment = $line.Deployment

}

 

I guess this is because csv data is not considered like object right ? How can I do what I’d like to do here ?

 

Thanks for your help folks !

Narwo

When you utilize Import-Csv it is importing it into Powershell as a Powershell object. You’re not showing how you are using the variables and what is wrong. Are they null? The below works properly, so provide additional detail on what exactly isn’t working for you.

$csv = @"
Device,Deployment
Device1,Deployment1
Device1,Deployment2
Device2,Deployment1
"@ | ConvertFrom-Csv


foreach ($line in $csv) {
    'Processing {0} for deployment {1}' -f $line.Device, $line.Deployment
}