1
My client's PowerShell scripts aren't working for a new user who happens to have a single-quote in their name - which means their profile path is called "C:\Users\Liam'OReilly". It appears to be a bug in the PowerShell class system.
Create a folder called "C:\Temp'Test" and add Test.ps1:
Write-Host "Test"
Class MyClass {}
Execute this script and you get this error:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) At line:1 char:1 + & 'C:\Temp''Test\Test..ps1' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], FileLoadException + FullyQualifiedErrorId : System.IO.FileLoadException
Rename the folder as simply C:\Test and it runs without an error.
Anyone got a workaround and what would be the best way to report this bug?
My workaround right now (as the user starts on Monday) is to remove the single-quote character from their display name in Office 365 which isn't ideal.
Honestly the best would be to remove the single quote from the name on the domain side. You can still keep the single quote in the display name, so the only change, would be the directory that is created on a domain connected computer. Otherwise you have to manually modify the registry on each device connected to the domain they log into. As for reporting the bug, report it to the PowerShell Core team, should be fixed in PowerShell 5.
– Ramhound – 2018-05-17T10:44:51.187Scratch that. PowerShell 5.1 appears to be the last (closed source) version. By reporting it to the PowerShell Core team it will be fixed eventually. You should verify the current beta version of PowerShell Core does not have this problem though (before you report it) – Ramhound – 2018-05-17T10:51:19.873
Thx - in Office 365/Azure AD I had to rename the display name to "Liam OReilly" as this appears to be what controls the name of the user's profile directory – munrobasher – 2018-05-17T10:51:43.300
Problem was already reported and fixed to the PowerShell Core team by the way. I went ahead and flagged this as a duplicate, since the issue was reported, and it referenced a question asked here. My assumption is that by the reported issue being fixed, while slightly different, the problem you discovered will also be fixed. – Ramhound – 2018-05-17T10:55:32.843
Possible duplicate of "Open PowerShell window here" File Explorer context-menu command breaks with folder names with apostrophes (single quotes)
– Ramhound – 2018-05-17T10:56:26.123Whilst this flaw is definitely in the same area, it's not the same bug as referred above. You can run the script using the File Explorer content menu (so that bug has been fixed) but this is a different error with the class statement – munrobasher – 2018-05-17T11:01:43.687
Then I encourage you to report the issue, but based on what read, the behavior you discovered is more or less intended based on design choices. Now I won't argue a way around that intended design choice should exist but it seems the problem surrounding a single quote existing in the directory is because of a long standing design decision within PowerShell itself (and it likely will not be fixed in PowerShell 5.1 so you will have to use PowerShell Core if it is fixed) – Ramhound – 2018-05-17T11:04:09.273