Get-ChildItem and non-breaking space Get-ChildItem and non-breaking space powershell powershell

Get-ChildItem and non-breaking space


As mentioned in the comment, you found an actual error that will hopefully soon being fixed.

However, there is a very acceptable workaround that you can apply with minimal effort while continuing to use Get-ChildItem without the need to exclude your folder.

The Unicode version of Get-ChildItem does not suffer from this problem. (Tested on Powershell 5.1 on a Windows 10 environment)To use it, simply replace

Get-ChildItem  -Path 'c:\__tmp' -recurse 

by

Get-ChildItem  -LiteralPath '\\?\c:\__tmp' -recurse 

Additional note

If you need to deal with UNC, the UNC unicode call is slightly different.

Get-ChildItem  -LiteralPath '\\?\UNC\127.0.0.1\c$\__tmp' -recurse 

Notice that I use for this to work properly the -LiteralPath parameter instead of -Path.

References

From Microsoft documentation

-LiteralPath

Specifies a path to one or more locations. Unlike the -Path parameter, the value of the -LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

source

Regarding the unicode prefix convention: Naming Files, Paths, and Namespaces

BonusThe unicode call also have the benefit of solving the 260 characters path length limit : see here