【发布时间】:2019-07-11 18:51:07
【问题描述】:
我认为这是一个仅适用于 PowerShell Windows 5.1 的错误:
当通过命名的-InputObject 参数提供输入时,-NoEnumerate 开关不起作用:
以下函数返回False:
Function Test {Write-Output -InputObject (,'Foo') -NoEnumerate}
(Test) -is [Array]
虽然这个函数返回True:
Function Test {Write-Output (,'Foo') -NoEnumerate}
(Test) -is [Array]
PowerShell Windows
Name Value
---- -----
PSVersion 5.1.17134.858
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.858
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
问题没有显示在 PowerShell Core 中。
(两个函数都返回True)
Name Value
---- -----
PSVersion 6.2.0-preview.1
PSEdition Core
GitCommitId 6.2.0-preview.1
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
虽然在Write-Output cmdlet 的描述中有一条关于-NoEnumeration 开关的说明:
注意
此开关仅适用于 PowerShell Core 6.2 及更高版本。 在旧版本的 PowerShell Core 上,集合仍然是 即使使用此开关也会枚举。 PowerShell 中的行为 Core 6.2 与 Windows PowerShell 一致。
(如果我没看错,我知道-NoEnumeration 开关应该只适用于 PowerShell Windows)
我已按照PowerShell GitHub Community 的指导here 在Windows PowerShell [UserVoice] 上报告了问题here,但感觉就像一个黑洞......(我之前报告过问题但几乎没有看到任何回应)。
问题:
这确实是一个错误还是我错过了什么?
如果是错误,Windows PowerShell [UserVoice] 仍然是报告此类问题的正确地址吗?
【问题讨论】:
-
是的,这是一个已知的错误。不,你不能把它修好。它最近在 v6.2 中得到修复
-
@TheIncorrigible1,感谢您的回答。我遇到了这个问题,但无法将它与它对我的看法联系起来:使用(而不是使用)命名的
-InputObject参数)。 -
您的问题中引用的文档在撰写本文时确实不正确。已在this GitHub issue 中请求修复它们。
标签: windows powershell switch-statement enumerate