The MyDocuments folder on my workstation is set to "C:\Stefan's Documents".
My Powershell command prompt shortcut is configured to start in this folder
(i.e. the "Start In" property of the shortcut). Whenever I start a
Powershell command prompt I get the following error:
<Snip>
Copyright (C) 2006 Microsoft Corporation. All rights reserved.
Incomplete string token.
At line:1 char:27
+ set-location 'C:\Stefan's D <<<< ocuments'
PS C:\Stefan's Documents>
</Snip>
This is pretty annoying. I've tracked the bug down to the following line in
the Microsoft.Powershell.ConsoleHost.InitializeRunspace:
string command = StringUtil.Format("set-location '{0}'",
Environment.CurrentDirectory);
The resultant command is "set-location 'C:\Stefan's Documents'". The
apostrophe in the directory name has not been escaped properly. This issue
gets worse if you create a profile in this directory (i.e. $profile =
C:\Stefan's Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1).
<Snip>
Windows PowerShell
Copyright (C) 2006 Microsoft Corporation. All rights reserved.
Incomplete string token.
At line:1 char:27
+ set-location 'C:\Stefan's D <<<< ocuments'
Incomplete string token.
At line:1 char:17
+ . 'C:\Stefan`'s D <<<<
ocuments\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
PS C:\Stefan's Documents>
</Snip>
In this case the code that runs profile includes a call to the
EscapeTickCharacters function (see
Microsoft.Powershell.ConsoleHost.RunProfile). This function prefixes an
apostrophe (') with a backwards apostrophe (`). According to "get-help
about_escape_character' (`') should escape the apostrophe. This second error
message must therefore be a bug in the parser / tokenizer (probably
StringTokenReader).
I've logged this as a bug in Connect,
https://connect.microsoft.com/feedba...8008&SiteID=99
--
Cheers,
Stefan Delmarco | SQL Server MVP | http://www.fotia.co.uk/


