locked
column is breaking after exporting CSV RRS feed

  • Question

  • I am creating CSV in following form.

    Path | Type |Old File Name |New File Name | Action| Error Message
    \\homedrive\userName\Home | VERBOSE | \\homedrive\userName\Home\Favorites\Links\Unable to open .oft files by directly opening them. (Double-Click on them from file share, etc).url | \\homedrive\userName\Home\Favorites\Links\Unable to open .oft files by directly opening them. (Double-Click on th.url | To be renamed | Filename too long.
    \\homedrive\userName\Home | VERBOSE | \\homedrive\userName\Home\Favorites\Links\Unable to open .oft files by directly opening them. (Double-Click on them from file share, etc).url | \\homedrive\userName\Home\Favorites\Links\Unable to open .oft files by directly opening them. (Double-Click on th1.url | To be renamed | Filename too long.

    Then importing same CSV to remove duplicate rows using following command. Till here it is working perfect

    $inputcsv = Import-Csv $logLocation | Sort-Object * -Unique 

    Then exporting CSV again as

    $inputcsv | Export-Csv $CentralLog -NoTypeInformation

    After exporting that I notied column 3 is terminating because column contains comma(,) character. For example if you see above csv column 3, which is containing comma character after share keywords. I am not sure why it is breaking the column when column 3 contains any comma character. I already delimited the file by pipe (|) character.

    "Path | Type |Old File Name |New File Name | Action| Error Message"
    "\\homedrive\userName\Home | VERBOSE | \\homedrive\userName\Home\Favorites\Links\Unable to open .oft files by directly opening them. (Double-Click on them from file share"

    I am not sure what I am missing here.

    Avian

    Thursday, July 20, 2017 1:16 PM

All replies

  •  Import-Csv$logLocation  -Delimiter '|'

    help Import-Csv -Full


    \_(ツ)_/

    Thursday, July 20, 2017 1:44 PM
  • Hi jrv

    As you suggested, I tried

    $inputcsv = Import-Csv $input -Delimiter "|" -Encoding UTF8| Sort-Object * -Unique 

    Then I export again as

    $inputcsv | Export-Csv $adminLog -Delimiter "|" -NoTypeInformation 

    I am getting following error

    Error! You cannot call a method on a null-valued expression

    However if I export without pipe delimiter it is exporting with comma delimited correctly. But I want to export as pipe delimiter.


    • Edited by Avian123 Thursday, July 20, 2017 2:03 PM
    Thursday, July 20, 2017 2:02 PM
  • You cannot use "$input" as a variable.  It is reserved by PowerShell.

    Try the following to see what happens

    $input = 'test'
    $input


    \_(ツ)_/

    Thursday, July 20, 2017 2:05 PM
  • As you suggested I changed the variable name $input to $InCSV. But it is not affecting my export output.
    Thursday, July 20, 2017 2:14 PM
  • Then your input file is no really a true CSV.

    $inputcsv = Import-Csv$logLocation -Delimiter '|'

    Now look at the CSV object to see what it looks like.


    \_(ツ)_/

    Thursday, July 20, 2017 2:35 PM
  • Hi,
    Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance.

    Best Regards,

    Frank

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, August 11, 2017 4:44 AM