我正在尝试创建一个使用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
我正在尝试将每个单独的行。
最佳答案
Tee-Object
不是您要的CmdLet,请尝试Set-content
和Add-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
Tee-Object
的目的实际上是在管道序列中充当“T”,以便从输入到输出以及向文件或变量发送数据(以调试管道序列为例)。关于不会覆盖文件的PowerShell Tee对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15696976/