Powershell添加内容截断输出 [英] Powershell Add-Content Truncating Output

查看:120
本文介绍了Powershell添加内容截断输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PowerShell脚本中使用Add-Content cmdlet将foreach循环中的匹配项写入单独的文本文件.为此,我使用以下代码:

I'm using the Add-Content cmdlet in a PowerShell script to write the matches in a foreach loop to a separate text file. To do this, I'm using the following code:

Add-Content -Path $varListNotFound $match

$varListNotFound包含文件名和路径,而$match是foreach循环中与我的项目范围匹配的变量.

The $varListNotFound contains the file name and path while the $match is the variable in the foreach loop that is being matched in my range of items.

我不确定是否会有所作为,但是我要匹配的匹配项是从XML文档中提取的.

I'm not sure if it makes a difference, but the matches I'm matching are being pulled from an XML document.

在输出文本文件中,除非名称很长,否则将正确输出在XML文件的<name></name>节点中找到的匹配项.如果名称太长,则会将名称截断为76个字符,并在其后添加三个句点.这导致我正在使用的这行代码清除未使用的项目:

In the output text file, the matches found in the <name></name> node of my XML file are output correctly unless the name is long. When the name is too long, it is truncating the name to 76 characters and adding three periods after it. This is causing problem with this line of code that I'm using the clear out the unused items:

$xml.rhpml.variables.variable | ? { $varRemove -contains $_.name } | % {$xml.rhpml.variables.RemoveChild($_)}

我已添加到脚本中,以便可以从截断末尾删除省略号,但是被截断的名称并未从XML文档中删除.

I've added to my script so that I can remove the ellipses from the end of the truncation, but the truncated name is not being removed from the XML document.

是否有一种方法可以扩展Add-Content的长度?还是有一种方法可以使上面的XML代码不排除被截断的名称?

Is there a way to extend the length of the Add-Content? Or is there a way to get the above XML code to not exclude the truncated names?

我尝试将$varRemove -contains $_.name更改为$varRemove -like$_.name,但是并没有从XML中删除节点.

I tried changing $varRemove -contains $_.name to $varRemove -like$_.name, but it didn't remove the nodes from the XML.

推荐答案

尝试使用Out-File cmdlet代替Add-Content,并指定Append和Width属性.

Try using the Out-File cmdlet instead of Add-Content, and specify the Append and Width properties.

这篇关于Powershell添加内容截断输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆