ConvertTo-Csv Output without quotes

前端 未结 14 1039
慢半拍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 08:35

    Here's another approach:

    Get-Process | ConvertTo-Csv -NoTypeInformation -Delimiter "," | 
        foreach { $_ -replace '^"|"$|"(?=,)|(?<=,)"','' }
    

    This replaces matches with the empty string, in each line. Breaking down the regex above:

    • | is like an OR, used to unite the following 4 sub-regexes
    • ^" matches quotes in the beginning of the line
    • "$ matches quotes in the end of the line
    • "(?=,) matches quotes that are immediately followed by a comma
    • (?<=,)" matches quotes that are immediately preceded by a comma

提交回复
热议问题