我需要一个powershell脚本来自动化将数据保存到文本文件的任务,而无需在迭代过程中替换旧文件

我需要一个powershell脚本来自动化将数据保存到文本文件的任务,而无需在迭代过程中替换旧文件,powershell,Powershell,我有一个.ps1文件,每当TFS调用它时都会执行它,它的输出将保存到特定的文件(D:/Deploytest/output/output.txt)。如果第二次触发脚本,则output.txt文件将替换为新内容。如何将旧文件保留在文件夹中并将输出添加到新文件? 我在.ps1文件中使用了以下命令。如何修改以实现我的任务。 Invokesqlcmd-Inputfile“path”| out file“D:/Deploytest/output/output.txt” 谢谢。如果要保留该文件,请将名称设置为

我有一个.ps1文件,每当TFS调用它时都会执行它,它的输出将保存到特定的文件(D:/Deploytest/output/output.txt)。如果第二次触发脚本,则output.txt文件将替换为新内容。如何将旧文件保留在文件夹中并将输出添加到新文件? 我在.ps1文件中使用了以下命令。如何修改以实现我的任务。
Invokesqlcmd-Inputfile“path”| out file“D:/Deploytest/output/output.txt”


谢谢。

如果要保留该文件,请将名称设置为动态(可能是时间戳)或
-append
。类似于:
out file“D:/Deploytest/output/output$(get date-Format MMddhhmm).txt“
如果要保留该文件,请将名称设置为动态(可能是时间戳)或
-append
。类似于:
out file“D:/Deploytest/output/output$(获取日期-格式MMddhhmm).txt”
#create path output file horodated
$Outfilename="D:/Deploytest/output/output_{0:yyyyMMddhhmmssffff}.txt" -f (get-date)

#out you command into this file
invoke-sqlcmd -Inputfile "path" | out-file $Outfilename