Eric Eric - 1 year ago 274
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?

Answer Source

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 '.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download