Why doesn't PowerShell Core 7 recognize UNC paths when Windows PowerShell and cmd do?
Your path syntax is unrelated to UNC paths; it uses a special prefix[1], \\?\
, whose purpose is to opt into support for file-system paths whose length exceeds 259
characters.
In Windows PowerShell (the legacy PowerShell edition that ships with Windows, whose latest and final version is v5.1):
\\?\
is supported, as shown in your question.
In PowerShell (Core) 6+ (the cross-platform, install-on-demand edition):
\\?\
is no longer needed, because long paths are supported by default.That said, it should still be supported - not least in order to support code that runs in both PowerShell editions - and the fact that it isn't, as of PowerShell 7.2 - situationally resulting in no output, with wildcard paths,
Get-ChildItem -Path \\?\C:\Users\*
, or with the root directory's content(!), with literal pathsGet-ChildItem -LiteralPath \\?\C:\Users
- is the subject of GitHub issue #10805.
[1] Such prefixes identify Win32 namespaces. The specifics of \\?\
are explained here.
Given this convention is specific to Win32 (and PowerShell has been re-written to be cross-platform), it is likely that this is simply not supported any longer.
If you have other parts of the code that expect this format, a well-placed inline -replace
can strip it off
$("\\?\C:\Users\*" -replace '\\\\\?\\', '')