不覆盖文件的PowerShell Tee对象

不覆盖文件的PowerShell Tee对象,powershell,powershell-2.0,Powershell,Powershell 2.0,我试图创建一个应用程序,使用将变量放入文件(minedown.conf)中,但每次它向文件添加内容时,都会覆盖它。我正在使用 $account = Read-Host "Enter your Account SID number" "account = $account" | Tee-Object -FilePath c:\minedown\minedown.conf $token = Read-Host "Enter your Authority Token" "token = $token"

我试图创建一个应用程序,使用将变量放入文件(minedown.conf)中,但每次它向文件添加内容时,都会覆盖它。我正在使用

$account = Read-Host "Enter your Account SID number"
"account = $account" | Tee-Object -FilePath c:\minedown\minedown.conf
$token = Read-Host "Enter your Authority Token"
"token = $token" | Tee-Object -FilePath c:\minedown\minedown.conf
$from = Read-Host "Enter your Twilio number"
"from - $from" | Tee-Object -FilePath c:\minedown\minedown.conf

我正在尝试将这些设置为单独的一行。

Tee对象
不是您要查找的CmdLet,请尝试
设置内容
添加内容

$account = Read-Host "Enter your Account SID number"
"account = $account" | Set-content -Path c:\minedown\minedown.conf
$token = Read-Host "Enter your Authority Token"
"token = $token" | Add-Content -Path c:\minedown\minedown.conf
$from = Read-Host "Enter your Twilio number"
"from - $from" | Add-Content -Path c:\minedown\minedown.conf

Tee对象的目的实际上是充当管道序列中的“T”,以便将数据从输入发送到输出,并发送到文件或变量(例如调试管道序列)。

另一方面,在PowerShell 3.0中,将-Append开关添加到
Tee对象
cmdlet。

如前所述,Tee对象(别名
Tee
)用于将输出拆分为两个方向。在Linux(
tee
)上,它对于转到屏幕和文件非常有用。在PowerShell中,它更多的是用于将其放在屏幕上,并将其返回到管道中以及其他内容,但不能执行追加操作。不是你想要的那样

然而,我需要用Linux的方式,让它显示在屏幕上,并写入一个文件(在附加模式下)。因此,我首先使用下面的方法将其写入管道,然后将其放入屏幕(使用颜色),并将其放入一个文件中,该文件将被附加到管道中,而不仅仅是被覆盖。也许它对某人有用:

Write-Output "from - $from" | %{write-host $_ -ForegroundColor Blue; out-file -filepath c:\minedown\minedown.conf -inputobject $_ -append}

添加内容:找不到与参数名称“Filepath”匹配的参数。在C:\Users\Zoey\Desktop\Minedown\test.ps1:25 char:45+“account=$account”| Add Content-Filepath@zoeycluff中,正确的参数是
-path
。只要稍加努力,您就可以使用“get-help add content-full”来发现它。谢谢@C.B,我只是复制了过去更改CmdLet名称的内容。@JPBlanc我也是复制粘贴的受害者;)