Hello Phil,
I've had an attempt at this, but i get mixed results, either the double quotes are before the drive letter or the entire string is wrapped in double quotes. Little bit confused.
That's ok, we got this.
In PowerShell, the double quotes character (") has a special meaning (also the single quote). Let's have a look on the following example:
We have a variable to which we assign a value, i.e.:
If we encapsule our variable between single quotes:
the shell will return the following:
As it can be seen, the shell will return the
name of the variable.
When encapsuled between double quotes:
the shell will return:
As it can be seen, the shell will now return the
value of the variable.
Normally, when you want to use a single/double quote inside another double quote, the characters must be escaped. The escape character (`) will tell the shell that it needs to take the literal value. For example, if we want to print in the shell the following string:
The value of $var is string
we will use something similar to this:

- PS.png (65.32 KiB) Viewed 4882 times
Now, coming back to the main problem. If you want to encapsule between double quotes each element of the array, you can proceed as it follows:
Code: Select all
$drives = Get-PsDrive -PSProvider FileSystem | Select Root
for($i = 0; $i -lt $drives.Count; $i++){
$temp = -join ($drives[$i].Root,'|')
$new += "`"$temp`""
}
Notice that when we create the $new variable, we have escaped the double quote character. The two furthermost (first and last) quotes have the job to expand the value of the $temp variable while the escaped quotes have the job encapsule them between quotes.
Hope this helps and I hope you don't mind the little explanation.
Best regards,
Catalin
FOLLOW US
Get the latest news in Application Packaging