PowerShell Tee-Object without overwriting file










5















I'm trying to create an application that puts variables in a file (minedown.conf) using Tee-Object, but every time it goes to add something to the file it overwrites it. I'm using



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


I'm trying to make each of those a separate line.










share|improve this question




























    5















    I'm trying to create an application that puts variables in a file (minedown.conf) using Tee-Object, but every time it goes to add something to the file it overwrites it. I'm using



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


    I'm trying to make each of those a separate line.










    share|improve this question


























      5












      5








      5


      1






      I'm trying to create an application that puts variables in a file (minedown.conf) using Tee-Object, but every time it goes to add something to the file it overwrites it. I'm using



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


      I'm trying to make each of those a separate line.










      share|improve this question
















      I'm trying to create an application that puts variables in a file (minedown.conf) using Tee-Object, but every time it goes to add something to the file it overwrites it. I'm using



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


      I'm trying to make each of those a separate line.







      powershell powershell-v2.0






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 3:32









      Peter Mortensen

      13.7k1986113




      13.7k1986113










      asked Mar 29 '13 at 3:43









      zoey cluffzoey cluff

      63128




      63128






















          3 Answers
          3






          active

          oldest

          votes


















          4














          Tee-Object is not the CmdLet you are looking for, try Set-content and Add-Content.



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


          The purpose of Tee-Object is really to act as a 'T', in a pipe sequence, in order to send data from the input to output and to a file or a variable (in order to debug a pipe sequence for exemple).






          share|improve this answer

























          • Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

            – zoey cluff
            Mar 29 '13 at 4:35






          • 3





            @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

            – CB.
            Mar 29 '13 at 7:55












          • Thanks @C.B, I just copy past changing the CmdLet name.

            – JPBlanc
            Mar 29 '13 at 10:09











          • @JPBlanc I am also often a victim of copy&paste ;)

            – CB.
            Mar 29 '13 at 10:11


















          8














          As an aside, in PowerShell 3.0, the -Append switch was added to the Tee-Object cmdlet.






          share|improve this answer






























            1














            As mentioned, Tee-Object (alias tee) is for splitting output into two directions. On Linux (tee) it is useful for going to screen & file. In PowerShell it is more for putting to screen and throwing it back on the pipeline as well as other stuff, but cannot do Append. Not really how you want it.



            However, I needed to do the Linux way and have it show on the screen as well as write to a file (in append mode). So I used the below method to write it onto the pipeline first, then put it to the screen (with colors) and put it in a file that is being appended to rather than just overwritten. Maybe it will be useful to someone:



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





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15696976%2fpowershell-tee-object-without-overwriting-file%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              Tee-Object is not the CmdLet you are looking for, try Set-content and Add-Content.



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


              The purpose of Tee-Object is really to act as a 'T', in a pipe sequence, in order to send data from the input to output and to a file or a variable (in order to debug a pipe sequence for exemple).






              share|improve this answer

























              • Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

                – zoey cluff
                Mar 29 '13 at 4:35






              • 3





                @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

                – CB.
                Mar 29 '13 at 7:55












              • Thanks @C.B, I just copy past changing the CmdLet name.

                – JPBlanc
                Mar 29 '13 at 10:09











              • @JPBlanc I am also often a victim of copy&paste ;)

                – CB.
                Mar 29 '13 at 10:11















              4














              Tee-Object is not the CmdLet you are looking for, try Set-content and Add-Content.



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


              The purpose of Tee-Object is really to act as a 'T', in a pipe sequence, in order to send data from the input to output and to a file or a variable (in order to debug a pipe sequence for exemple).






              share|improve this answer

























              • Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

                – zoey cluff
                Mar 29 '13 at 4:35






              • 3





                @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

                – CB.
                Mar 29 '13 at 7:55












              • Thanks @C.B, I just copy past changing the CmdLet name.

                – JPBlanc
                Mar 29 '13 at 10:09











              • @JPBlanc I am also often a victim of copy&paste ;)

                – CB.
                Mar 29 '13 at 10:11













              4












              4








              4







              Tee-Object is not the CmdLet you are looking for, try Set-content and Add-Content.



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


              The purpose of Tee-Object is really to act as a 'T', in a pipe sequence, in order to send data from the input to output and to a file or a variable (in order to debug a pipe sequence for exemple).






              share|improve this answer















              Tee-Object is not the CmdLet you are looking for, try Set-content and Add-Content.



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


              The purpose of Tee-Object is really to act as a 'T', in a pipe sequence, in order to send data from the input to output and to a file or a variable (in order to debug a pipe sequence for exemple).







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 29 '13 at 18:54

























              answered Mar 29 '13 at 4:10









              JPBlancJPBlanc

              52.6k1092129




              52.6k1092129












              • Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

                – zoey cluff
                Mar 29 '13 at 4:35






              • 3





                @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

                – CB.
                Mar 29 '13 at 7:55












              • Thanks @C.B, I just copy past changing the CmdLet name.

                – JPBlanc
                Mar 29 '13 at 10:09











              • @JPBlanc I am also often a victim of copy&paste ;)

                – CB.
                Mar 29 '13 at 10:11

















              • Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

                – zoey cluff
                Mar 29 '13 at 4:35






              • 3





                @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

                – CB.
                Mar 29 '13 at 7:55












              • Thanks @C.B, I just copy past changing the CmdLet name.

                – JPBlanc
                Mar 29 '13 at 10:09











              • @JPBlanc I am also often a victim of copy&paste ;)

                – CB.
                Mar 29 '13 at 10:11
















              Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

              – zoey cluff
              Mar 29 '13 at 4:35





              Add-Content : A parameter cannot be found that matches parameter name 'Filepath'. At C:UsersZoeyDesktopMinedowntest.ps1:25 char:45 + "account = $account" | Add-Content -Filepath <<<< Path c:minedownminedown.conf + CategoryInfo : InvalidArgument: (:) [Add-Content], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.AddContentCommand

              – zoey cluff
              Mar 29 '13 at 4:35




              3




              3





              @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

              – CB.
              Mar 29 '13 at 7:55






              @zoeycluff The correct parameter is -path. With a little effort you could discover it using ` get-help add-content -full`.

              – CB.
              Mar 29 '13 at 7:55














              Thanks @C.B, I just copy past changing the CmdLet name.

              – JPBlanc
              Mar 29 '13 at 10:09





              Thanks @C.B, I just copy past changing the CmdLet name.

              – JPBlanc
              Mar 29 '13 at 10:09













              @JPBlanc I am also often a victim of copy&paste ;)

              – CB.
              Mar 29 '13 at 10:11





              @JPBlanc I am also often a victim of copy&paste ;)

              – CB.
              Mar 29 '13 at 10:11













              8














              As an aside, in PowerShell 3.0, the -Append switch was added to the Tee-Object cmdlet.






              share|improve this answer



























                8














                As an aside, in PowerShell 3.0, the -Append switch was added to the Tee-Object cmdlet.






                share|improve this answer

























                  8












                  8








                  8







                  As an aside, in PowerShell 3.0, the -Append switch was added to the Tee-Object cmdlet.






                  share|improve this answer













                  As an aside, in PowerShell 3.0, the -Append switch was added to the Tee-Object cmdlet.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 29 '13 at 10:18









                  Shay LevyShay Levy

                  87.2k17137157




                  87.2k17137157





















                      1














                      As mentioned, Tee-Object (alias tee) is for splitting output into two directions. On Linux (tee) it is useful for going to screen & file. In PowerShell it is more for putting to screen and throwing it back on the pipeline as well as other stuff, but cannot do Append. Not really how you want it.



                      However, I needed to do the Linux way and have it show on the screen as well as write to a file (in append mode). So I used the below method to write it onto the pipeline first, then put it to the screen (with colors) and put it in a file that is being appended to rather than just overwritten. Maybe it will be useful to someone:



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





                      share|improve this answer





























                        1














                        As mentioned, Tee-Object (alias tee) is for splitting output into two directions. On Linux (tee) it is useful for going to screen & file. In PowerShell it is more for putting to screen and throwing it back on the pipeline as well as other stuff, but cannot do Append. Not really how you want it.



                        However, I needed to do the Linux way and have it show on the screen as well as write to a file (in append mode). So I used the below method to write it onto the pipeline first, then put it to the screen (with colors) and put it in a file that is being appended to rather than just overwritten. Maybe it will be useful to someone:



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





                        share|improve this answer



























                          1












                          1








                          1







                          As mentioned, Tee-Object (alias tee) is for splitting output into two directions. On Linux (tee) it is useful for going to screen & file. In PowerShell it is more for putting to screen and throwing it back on the pipeline as well as other stuff, but cannot do Append. Not really how you want it.



                          However, I needed to do the Linux way and have it show on the screen as well as write to a file (in append mode). So I used the below method to write it onto the pipeline first, then put it to the screen (with colors) and put it in a file that is being appended to rather than just overwritten. Maybe it will be useful to someone:



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





                          share|improve this answer















                          As mentioned, Tee-Object (alias tee) is for splitting output into two directions. On Linux (tee) it is useful for going to screen & file. In PowerShell it is more for putting to screen and throwing it back on the pipeline as well as other stuff, but cannot do Append. Not really how you want it.



                          However, I needed to do the Linux way and have it show on the screen as well as write to a file (in append mode). So I used the below method to write it onto the pipeline first, then put it to the screen (with colors) and put it in a file that is being appended to rather than just overwritten. Maybe it will be useful to someone:



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






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 15 '18 at 4:06









                          Peter Mortensen

                          13.7k1986113




                          13.7k1986113










                          answered May 10 '13 at 16:27









                          JoeBJoeB

                          1,18277




                          1,18277



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15696976%2fpowershell-tee-object-without-overwriting-file%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3

                              Museum of Modern and Contemporary Art of Trento and Rovereto