[英]Deferred PowerShell command Output
I have a PowerShell script.我有一个 PowerShell 脚本。 Sometimes a command fails but only outputs a message (no error code) that will be missed due to other commands executing.
有时一个命令失败,但只输出一条消息(没有错误代码),由于其他命令的执行而会遗漏该消息。
I don't have an error code to handle, can't break execution and can't match the text output to determine if its an error as it varies widely.我没有要处理的错误代码,无法中断执行并且无法匹配文本输出以确定它是否是错误,因为它变化很大。
How can I capture that commands output so I can display it at the end of the script?如何捕获该命令输出以便我可以在脚本末尾显示它?
This can be found in the error object.这可以在错误对象中找到。 Error is an array of errors, and
[0]
is the latest error to occur. Error 是一个错误数组,
[0]
是最近发生的错误。 Error is an object that can be viewed.错误是一个可以查看的对象。
($Error[0]).InvocationInfo.Line
The line above will give you the whole line in the script, that generated the error.上面的行将为您提供脚本中产生错误的整行。 The
InvocationInfo
property will not exist for errors from the command line.对于来自命令行的错误,将不存在
InvocationInfo
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.