Powershell Array to comma separated string with Quotes
Here you go:
[array]$myArray = '"file1.csv"','"file2.csv"'[string]$a = $null$a = $myArray -join ","$a
Output:
"file1.csv","file2.csv"
You just have to get a way to escape the "
. So, you can do it by putting around it '
.
I know this thread is old but here are other solutions
$myArray = "file1.csv","file2.csv"# Solution with single quote$a = "'$($myArray -join "','")'"$a# Result = 'file1.csv','file2.csv'# Solution with double quotes$b = '"{0}"' -f ($myArray -join '","')$b# Result = "file1.csv","file2.csv"
If using PowerShell Core (currently 7.1), you can use Join-String
This is not available in PowerShell 5.1
$myArray | Join-String -DoubleQuote -Separator ','
Output:
"file1.csv","file2.csv"