Editing a file from powershell

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of James Krusic James Krusic 2 months, 1 week ago.

  • Author
    Posts
  • #61983
    Profile photo of flouflis
    flouflis
    Participant

    Greetings,

    i am a newbie regarding powershell, i have searched the internet with no luck.

    my question is, is there a way to open a text file inside powershell and edit it live?

    for instance, instead of typing: notepad c:\textfile.txt
    a window of the textfile opens, edit it, click save and close.
    just to open the contend inside powershell, edit them there, and click save somehow.

    i remember, back when i was a student, in linux was possible, can't figure out how to do it in a powershell,

    thanks in advance.

  • #61986
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Hmmm ... what did you search for? It's hard to believe that you don't find one of the simplest tasks. You might start learning the Powershell basics. Here are some great free sources to look at:

    https://powershell.org/forums/topic/using-csv-files/

    BTW: A quick Google search for "powershell edit text file line" brought up this as the first hit:

    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/6ad028d9-551a-4934-b200-be22dae1597d/help-with-a-powershell-script-to-find-and-replace-a-line-of-text?forum=ITCG

    So you might even improve your search skills a little bit. 😉

    • #61987
      Profile photo of flouflis
      flouflis
      Participant

      thank you for your answer, but this not what i am looking for.

      i do not want to replace, change, delete or in general do something to a text file.

      i want the text file and it's contents to been shown inside powershell, and have the full control
      of the content inside powershell to edit them (do whatever i want using my mouse, or arrows to navigate)

      it's like having notepad in front of me, but powershell instead.

  • #61989
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    Why do you want to do Powershell the job of an editor? That doesn't make that much sense for me.

    To show the content of a text file you can use the cmdlet Get-Content.

  • #61990
    Profile photo of Don Jones
    Don Jones
    Keymaster

    PowerShell doesn't have anything like Nano or Vi, no. That's more a lack of Windows than PowerShell per se; PowerShell is just a command language. Windows hasn't really ever had a console editor. I haven't looked to see if some third party has made one or not, but that might be an option.

  • #61992
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    If you're looking for an IDE – the Powershell_ISE comes with Powershell or the MS Visual Studio Code with the Powershell extension does a good job I think.

  • #61993
    Profile photo of James Krusic
    James Krusic
    Participant

    So vi would be like psedit inside powershell ise using v5. Vi just opens the item to be edited inside the vi component much like editing a script inside ise.

You must be logged in to reply to this topic.