编辑和合并xml文件而不修改输入文件

时间:2016-08-12 18:46:56

标签: powershell powershell-v2.0

我的任务是将两个xml文件合并在一起。在合并这两个文件之前,我需要删除第二个文件的第一行。通过写这两行,我能够收到所需的输出文件:

#case if both files exists - remove first line from the file
(Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $JfilePath

#mergeFiles together
Get-Content $MfilePath, $JfilePath | Set-Content $mergedFile

问题是我正在通过执行第一个cmdlet来修改第二个文件。我想保留两个文件的原始形式。我不想也创建任何临时文件。 我试图执行以下操作:

 Get-Content $MfilePath, (Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $mergedFile

但我收到了错误:

Get-Content : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'LiteralPath'. Specified method is not supported.

请问如何在不修改这些输入文件的情况下帮助接收输出文件?

1 个答案:

答案 0 :(得分:1)

试试这个:

(Get-Content $MfilePath), (Get-Content $JfilePath | Select-Object -Skip 1) | Set-Content $mergedFile