I managed to get a " at the start of the UNC by joining the $replacement variable with a quote mark, but it leaves a space before the \ of the UNC path. Totally failed to find a way to remove the space, or how to add a quote mark at the end:
$replacement=($replacement + ' "')
The script basically collects an INI file, copies it to a home drive, then re-writes it into a PowerShell script that then maps a set of drives. Works a treat for 95% of users. But the 5% have spaces in the UNC path. Hence the need to add quotes around the UNC.
When the script collects the orignal INI file it looks like this:
New-PSDrive –Name I -Scope Global -Persist –PSProvider FileSystem –Root \\fileserv1\shared
New-PSDrive –Name M -Scope Global -Persist –PSProvider FileSystem –Root \\fileserv3\jondoe
But what I want is this:
New-PSDrive –Name I -Scope Global -Persist –PSProvider FileSystem –Root "\\fileserv1\shared"
New-PSDrive –Name M -Scope Global -Persist –PSProvider FileSystem –Root "\\fileserv3\jondoe"
New-PSDrive -Name I -Scope Global -Persist –PSProvider FileSystem –Root "\\fileserv1\shared"
New-PSDrive -Name M -Scope Global -Persist –PSProvider FileSystem –Root "\\fileserv3\jondoe"
Thank you for the suggestion about TRIM() for removing whitespace.
Any thoughts about how to get double quote marks over a variable length UNC path? I can get the first double quote marks in place and use the Trim to remove the whitespace. But still need to find a way to add double quote marks at the end.
is there a function that will find the last string character and append with " ?
Ah no sorry this still wont work. The final output (the bit with the UNC path) is not in a varaible. So:
$NewVar = $Var + "`""
Wont work. Also I am not trying to wrap " around -Scope Global -Persist –PSProvider FileSystem –Root.
This script is picking up an existing file (INI file) and converting it into PowerShell language. So the last bit of each line is a UNC path. I need to add a " onto the end of each line of that UNC path. So that UNC path is NOT in a variable.