ConvertTo-Csv Output without quotes

前端 未结 14 973
慢半拍i
慢半拍i 2020-12-01 08:03

I am using ConvertTo-Csv to get comma separated output

 get-process | convertto-csv -NoTypeInformation -Delimiter \",\"

It out

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 09:02

    This is pretty similar to the accepted answer but it helps to prevent unwanted removal of "real" quotes.

    $delimiter = ','
    Get-Process | ConvertTo-Csv -Delimiter $delimiter -NoTypeInformation | foreach { $_ -replace '^"','' -replace "`"$delimiter`"",$delimiter -replace '"$','' }
    

    This will do the following:

    • Remove quotes that begin a line
    • Remove quotes that end a line
    • Replace quotes that wrap a delimiter with the delimiter alone.

    Therefore, the only way this would go wrong is if one of the values actually contained not only quotes, but specifically a quote-delimiter-quote sequence, which hopefully should be pretty uncommon.

提交回复
热议问题