0

Came across a strange issue today when cloning my repository back down from GitHub.

An example would be the following line which works fine when ran independently in a local shell:

New-ItemProperty –Path HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\Identity\ –Name EnableADAL -Value 1 -PropertyType DWord -Force | Out-Null

However when you commit this to GitHub and then clone it back, it no longer runs and returns the error as below:

New-ItemProperty : Cannot find drive. A drive with the name 'â€Path HKCU' does not exist. At Z:\Outlook-Master-Tool\v1.2.prerelease.ps1:60 char:1

  • New-ItemProperty –Path HKCU:\SOFTWARE\Microsoft\Office\15.0\Common\ ...

As you can see, it adds †to the path somehow. Additionally, if you manually rewrite the command or copy the whole script into ISE, it runs fine.

What is going on? I really want to use GitHub for version control. I have a feeling it might be an encoding misconfiguration somewhere?

Thanks

  • Since the problem occurs with a _string literal_ in your _source code_, the likeliest explanation is that your script file is misinterpreted by the Windows PowerShell engine, which happens if the script is saved as UTF-8 _without a BOM_. Try saving your script as UTF-8 _with BOM_; see the linked duplicate for details. – mklement0 Sep 12 '22 at 14:22
  • 1
    Specifically, your script contains a parameter name that is prefixed with `–` (EN DASH, [`U+2013`](http://www.fileformat.info/info/unicode/char/2013)) character instead of the usual ASCII-range `-` (HYPHEN-MINUS, [`U+002D`](http://www.fileformat.info/info/unicode/char/2d)). That in itself is _not_ a problem, but because your UTF-8-encoded script file _lacks a BOM_, it is misinterpreted by _Windows PowerShell_, which sees the `–` as `â€"`. The solution is to save your script file as UTF-8 _with BOM_. – mklement0 Sep 12 '22 at 14:24

0 Answers0