ConvertFrom-Json是否尊重-ErrorAction

时间:2016-12-21 21:24:59

标签: json powershell error-handling

我正在编写一个需要解析JSON的脚本,并且我在某些文件上遇到错误。错误是由于无效的JSON,这很好,但我希望能够检测到这一点并在脚本中处理它。它看起来不像ConvertFrom-Json支持-ErrorAction。真的吗?我在网上看不到任何相关信息。

1 个答案:

答案 0 :(得分:2)

ErrorAction是PowerShell 2中添加的公共参数

来自ConvertFrom-JSON MSDN article

  

CommonParameters

     

此cmdlet支持常用参数:-Debug,-ErrorAction,   -ErrorVariable,-InformationAction,-InformationVariable,-OutVariable,-OutBuffer,-PipelineVariable,-Verbose,-WarningAction和-WarningVariable。有关更多信息,请参阅about_CommonParameters   (http://go.microsoft.com/fwlink/?LinkID=113216)。

编辑:这是PowerShell 5和6的bug logged on the PowerShell GitHub

相关问题