A small help about Converto-CSV

Welcome Forums General PowerShell Q&A A small help about Converto-CSV

This topic contains 3 replies, has 3 voices, and was last updated by

1 year ago.

  • Author
  • #99931

    Topics: 20
    Replies: 23
    Points: 107
    Rank: Participant

    Hi Team,

    I am trying to take multiple number input by user separated by comma and storing it into an array. After that trying to convert the value using convert CSV but not getting fruitful result. May be I am doing some conceptual mistakes. Can you please rectify me.

    $arr = @()
    $arr = Read-Host " Please input numbers" |ConvertTo-Csv -Delimiter ","

    The output I am getting if I input 10,20,30.

    PS C:\windows\system32> $arr
    #TYPE System.String

    Need your support.


  • #99934

    Topics: 1
    Replies: 1331
    Points: 1,680
    Helping Hand
    Rank: Community Hero

    Read-Host takes the input and creates one big string. If you like to split this in seperate numbers you will have to do it by yourself. ConvertTo-CSV would need some type or header information to work properly. It's more ConvertFrom-CSV what you're trying to do ...

  • #99939

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Agreed again. You've just got a basic misunderstanding about how the shell works ;).

    $arr in your script is not an array. It's a big string. Assuming the user typed something like:


    You could make an array by using

    $arr = $arr -split “,”
    • #99943

      Topics: 20
      Replies: 23
      Points: 107
      Rank: Participant

      Great... Split works as exactly what I am expecting. Thanks a lot. Thanks again for pointing out my mistakes.

The topic ‘A small help about Converto-CSV’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort