Eric Eric - 9 months ago 133
PowerShell Question

Powershell Array to comma separated string with Quotes

I have an array that I need to output to a comma separated string but I also need quotes "". Here is what I have.

$myArray = "file1.csv","file2.csv"
$a = ($myArray -join ",")

The output for

ends up


My desired output is


How can I accomplish this?


Here you go:

[array]$myArray = '"file1.csv"','"file2.csv"'
[string]$a = $null

$a = $myArray -join ","




You just have to get a way to escape the ". So, you can do it by putting around it '.