Convert .csv data to object

Welcome Forums General PowerShell Q&A Convert .csv data to object

Viewing 1 reply thread
  • Author
    Posts
    • #261917
      Participant
      Topics: 2
      Replies: 0
      Points: 14
      Rank: Member

      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

    • #261938
      Participant
      Topics: 16
      Replies: 1794
      Points: 3,300
      Helping Hand
      Rank: Community Hero

      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.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.