Change Text in a File with Powershell

B B 1 Reputation point
2021-04-24T12:01:15.163+00:00

I am looking to change the text of a specific line, but leave any remaining text within that file alone. Example:

Line 1 of file: Change Hey, how are you? to Hi, how are you?

I would like to change the Hey to Hi.

Line 2 of file: Hey, how are you?

No changes, leave it be.

Thanks to anyone for your help!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,443 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Chris 141 Reputation points
    2021-04-24T12:32:00.067+00:00

    Hi!
    Maybe this link will help or give some idea or turn point:
    replace-text-with-powershell.aspx

    0 comments No comments

  2. Andreas Baumgarten 101.2K Reputation points MVP
    2021-04-24T21:35:41.743+00:00

    Looks like this is almost the question in a different thread;
    https://learn.microsoft.com/en-us/answers/questions/369228/change-specific-text-in-a-file.html

    It would be helpful to focus in one thread. I will close this one.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments