【发布时间】:2021-08-16 15:46:44
【问题描述】:
PowerShell 似乎无法识别 \\?\ 表示法。为什么不呢?
=== cmd.exe
C:>ver
Microsoft Windows [Version 10.0.17763.1935]
C:>DIR "\\?\C:\Users\*"
Volume in drive \\?\C: is Windows
Volume Serial Number is 1C66-809A
Directory of \\?\C:\Users
2021-08-04 12:27 <DIR> .
2021-08-04 12:27 <DIR> ..
2019-11-25 16:22 <DIR> Administrator
... 0 File(s) 0 bytes
28 Dir(s) 81,919,647,744 bytes free
=== Windows powershell.exe
PS C:\Users> $PSVersionTable.PSVersion.ToString()
5.1.17763.1852
PS C:\Users> Get-ChildItem -Path "\\?\C:\Users\*"
Directory: \\?\C:\Users
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2019-11-25 15:22 Administrator
...
PS C:\Users>
=== PowerShell 核心 pwsh.exe
PS C:\Users> $PSVersionTable.PSVersion.ToString()
7.1.4
PS C:\Users> Get-ChildItem -Path "\\?\C:\Users\*"
PS C:\Users>
【问题讨论】:
-
我不知道为什么,但
Get-ChildItem -LiteralPath "\\?\C:\Users\"的工作原理可能与-Path中的通配符匹配有关 -
“为什么”很容易回答为“因为它是这样写的”;如果您想知道它是有意的还是错误的(如果是错误,是否要修复),PowerShell repo 似乎比 SO 更好。稍微搜索一下就给了我#10805,看起来它涵盖了这个。
-
@phuclv,如果你仔细观察,在 PS Core 中
Get-ChildItem -LiteralPath "\\?\C:\Users\"实际上并没有工作:虽然它确实产生了输出,但它错误地报告了 root 目录的内容(已验证在 PowerShell Core 7.2.0-preview.8 上)。
标签: powershell path filesystems powershell-core