powershell命令没有在输出文件中包括错误
我有以下代码,用于PowerShell;它的性能很好,除了我需要输出文件还可以在IPS不转为名称的情况下包括错误消息。
Get-Content inputfile.txt |
foreach-object { [System.Net.Dns]::GetHostEntry($_) } |
out-file -filepath outputfile.txt
目前,我可以看到PowerShell窗口上显示的红色错误消息。但是我希望这些出现在输出文件中,以及输入文件中列出的每个项目的结果。
提前致谢!
I have the code below, to be used in Powershell; it performed well, except that I need the output file to also include the error messages whenever the IPs did not resolve to names.
Get-Content inputfile.txt |
foreach-object { [System.Net.Dns]::GetHostEntry($_) } |
out-file -filepath outputfile.txt
At the moment, I'm able to see the red error messages displayed on Powershell window. But I want these to appear in the output file along with the results for each item listed in the input file.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为方法调用。这还允许您具有更好的导出类型,而不是普通的
.txt
文件,可以用.csv
将对象带有export> export-csv csv csv
。
Below example uses
Since
.GetHostEntry(..)
doesn't give you a clear hint as to which IP failed to be resolved it's better if you create an object that associates the IP Address you're trying to resolve with the method call. This also allows you to have a better export type, instead of plain.txt
file, you can export your objects as.csv
withExport-Csv
.Below example uses
.GetHostEntryAsync(..)
which allow us to query multiple hosts in parallel!