Powershell Add-Content Truncating Output

半世苍凉 提交于 2019-12-11 01:46:08

问题


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

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.

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

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($_)}

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.

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?

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


回答1:


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



来源:https://stackoverflow.com/questions/13074942/powershell-add-content-truncating-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!