1

我的问题与Hey Scripting Guy 的博客文章有关!由 Windows PowerShell (Azure) 团队的成员 June Blender 编写。

“要从 JSON 文件中获取 JSON 字符串,请使用 Get-Content cmdlet 及其 Raw 参数。”

   PS C:\> Get-Content -Raw -Path .\myJson.json

“Raw 参数告诉 Get-Content 忽略换行符并返回单个字符串。”

认为这看起来很方便 - 我想了解有关此参数的更多信息,我键入以下命令并收到意外结果:

    PS C:\> Update-Help
    PS C:\> Get-Help Get-Content -Parameter Raw
    Get-Help : No parameter matches criteria Raw. ##error etc.

    PS C:\> Get-Help Get-Content -Full | Out-String | Select-String 'Raw'
    PS C:\> 

在 ISE 中,intellisense 提供“raw”作为“Get-Content”的参数,而在正常的 shell 中,tab-complete 告诉我这是一个真实的参数。我似乎无法找到任何解释其用法的文档。“Help Get-Content -Online”也不返回任何内容。

    PS C:\> Get-Command * -ParameterName 'raw'
    Cmdlet      Get-Content        Microsoft.PowerShell.Management

Get-Command 确认参数存在,不是“通用参数”集的成员,并且存在于我的 PowerShell 版本中。我的问题:

为什么“Get-Content”的某些参数在我的帮助文件或在线中不可见,但仍然可以使用,特别是 -raw、-stream 和 -encoding。是否有其他 Cmdlet 的类似隐藏参数列表?

我在工作组环境中的 Windows 8.1 上运行 PowerShell v4。谢谢你的帮助。

更新:

    $PSVersionTable
    PSVersion                      4.0
    WSManStackVersion              3.0
    SerializationVersion           1.1.0.1
    CLRVersion                     4.0.30319.34014
    BuildVersion                   6.3.9600.16394
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
    PSRemotingProtocolVersion      2.2
    
    $PSUICulture; $PSCulture
    en-GB
    en-NZ
4

3 回答 3

4

这是动态参数的常见问题(并且-Raw,-Encoding就是这样的例子)。任何提供程序都能够使用动态参数扩展与提供程序相关的 cmdlet。仍然:如果您在正确的提供者中,我希望它可以正常工作。

即:如果您在 c:\ 驱动器上,您应该看到 Get-Content -Raw 的帮助。当您在不同的提供商(例如注册表)时,您确定没有尝试过吗?

对于联机帮助:您需要阅读提供程序帮助,而不是使用 cmdlet 帮助。cmdlet 的联机帮助无法猜测您所在的提供程序,因此它无法为您提供动态参数的帮助。

于 2014-05-12T15:13:49.317 回答
1

我已经在我的 Powershell(Windows 8.1 上的 V4)中尝试了你的命令。我得到了预期的结果并且没有错误:

PS C:\> get-help get-content -Parameter raw
-Raw <switch>
    Ignores newline characters and returns the entire contents of a file in on...

由于参数是在 PS3 中引入的,您是否像在 Exchange 2010 Shell 中那样在兼容模式下运行?什么显示了 $PSVersionTable 变量?

希望这可以帮助

于 2014-05-12T13:39:29.533 回答
0

我有相同版本的 PS / OS,但更新了帮助文件并获得以下信息:

C:\> help get-content -param raw

-Raw <switch>
    Ignores newline characters and returns the entire contents of a file in one string. By default, the contents of a file is returned as a array of strings that is delimited by
    the newline character.

因此,看起来您只是没有更新的帮助文件。

确保您处于提升的 PowerShell 提示符下(您通过右键单击它并键入以管理员身份运行来启动 PowerShell)然后运行

update-help -verbose -force

如果一切都失败了:

get-help get-content -online

http://technet.microsoft.com/library/hh847788(v=wps.630).aspx是您需要查看 raw 详细信息的地方,您应该能够通过在命令行上键入以下内容来获取它

我假设您有直接链接到互联网(不涉及代理等)

于 2014-05-12T16:18:50.360 回答