PowerShell Tee-Object无需覆盖文件

zoe*_*uff 5 powershell powershell-2.0

我正在尝试使用Tee-Object创建一个将变量放入文件(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
Run Code Online (Sandbox Code Playgroud)

我试图让每一个成为一条单独的线.

Sha*_*evy 10

另外,在PowerShell 3.0中,-Append开关已添加到Tee-Objectcmdlet中.


JPB*_*anc 4

Tee-Object不是您要找的 CmdLet,请尝试Set-contentAdd-Content

$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
Run Code Online (Sandbox Code Playgroud)

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

  • @zoeycluff 正确的参数是“-path”。只需付出一点努力,您就可以使用“ get-help add-content -full”来发现它。 (3认同)