我的问题与Windows PowerShell(Azure)团队成员June Blender在Hey Scripting Guy!的博客文章有关。
“要从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中告诉我它是一个真正的参数。我似乎无法找到任何解释它的用法的文档。 “帮助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
答案 0 :(得分:4)
动态参数的常见问题(以及-Raw
,-Encoding
就是这样的例子)。任何提供程序都能够使用动态参数扩展与提供程序相关的cmdlet。仍然:如果你是正确的提供者,我希望它能正常工作。
即:如果你在c:\驱动器上,你应该看到Get-Content -Raw的帮助。 当你在不同的提供者(例如注册表?)时,你确定你没有尝试过吗?
对于联机帮助:您需要阅读provider help,而不是使用cmdlet帮助。 cmdlet的在线帮助无法猜测您所在的提供商,因此它无法为您提供动态参数方面的帮助。
答案 1 :(得分: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变量?
希望这有帮助
答案 2 :(得分: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提示符下(右键单击并键入Run As Administrator启动PowerShell)然后 跑
update-help -verbose -force
如果一切都失败了:
get-help get-content -online
http://technet.microsoft.com/library/hh847788(v=wps.630).aspx是您需要查看raw的详细信息的地方,您应该可以通过在命令行键入以下内容来实现它
我假设您有直接链接到互联网(不涉及代理等)