powershell - 使用 Add-Content PowerShell 将文本添加到现有文件的新行

标签 powershell powershell-2.0 powershell-4.0

我正在尝试使用 get-content 从文件中获取内容并使用 add-content 将其添加到现有文件,但问题是我无法将该内容添加到新行。你能对此提出建议吗?

使用以下命令:

Get-content -Path $destRoot1 | Add-Content -Path $destRoot2 

最佳答案

您需要将内容设置为目标文件路径,而不是添加内容。请引用以下更改:

$destRoot1 = "C:\File\path1.txt"
$destRoot2 = "C:\destination\path\of\the\file.txt"
Get-content -Path $destRoot1 |Set-Content -Path $destRoot2 -Force

关于powershell - 使用 Add-Content PowerShell 将文本添加到现有文件的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66566109/

相关文章:

powershell - 添加xml属性 "xsi:nil"

powershell - 如何通过powershell删除文件夹的只读属性?

powershell - 与 Powershell 交换 - 奇怪的错误

datetime - 具有特定日期/时间范围的PowerShell脚本

powershell-2.0 - 无法用 PowerShell 2.0 替换文件名

powershell - 命令和ScriptBlock Powershell之间的区别

powershell - Powershell将文件路径中最后出现的 '/'替换为 '.'

powershell - 如何解决测试连接错误 : "A parameter cannot be found that matches parameter" name 'TargetName' . "

windows - Windows-从命令行为事件创建任务

Powershell:函数中的 $LASTEXITCODE