Powershell ISE Illegal characters in path with literalpath

Step to IT 80 Reputation points


I have encountered the problem of running PowerShell cmdlets using "LiteralPath" in PowerShell ISE, when folder is existing.

Error message:

Get-ChildItem : Illegal characters in path.
At line:1 char:1
+ Get-ChildItem -LiteralPath "\\?\C:\Test_Folder" -Directory -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand

What is interesting:

  • The error occurs on the Windows server (my version is 2022 with last updates), the error does not occur on the Windows desktop
  • The error occurs in PowerShell ISE, the error does not occur in PowerShell regular

Example of cmdlets:

Test-Path -LiteralPath "\\?\C:\Test_Folder"
Get-ChildItem -LiteralPath "\\?\C:\Test_Folder" -Directory -Recurse

What is the reason for this and how to deal with it?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,430 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,416 Reputation points

    Is it possible that the use of long file names hasn't been enabled?

    Check the LongPathsEnabled value in this registry key:


    If it isn't set to "1", change it to "1" and reboot the machine.

  2. Rich Matheisen 45,416 Reputation points

    Try it this way (it really shouldn't make any difference -- I expect it will still fail:

    $MyPath = "\\?\C:\Test_Folder"
    Test-Path -LiteralPath $MyPath

    Are you running PowerShell ISE 32-bit or 64-bit? Paste this into the ISE command prompt window and run it: [Environment]::Is64BitProcess. Do you get a True or False as the answer?

    Can you access a FILE (instead of a folder) using the long-file-name format and the -LiteralPath?

    Lastly, is there any reason you're using -LiteralPath and the long-file-name format? There's nothing in name that requires it.