We help IT Professionals succeed at work.
Get Started

Read from Text File and Replace String using Powershell

jskfan asked
Last Modified: 2019-12-08
Read from Text File and Replace String using Powershell

For now , I have this command below that works fine when I run it against one remote computer named Windows7 and Replacing one string "username" with "white"
but when I have many computers, then it  does not help

((Get-Content -Path '\\Windows7\c$\test.txt' -Raw) -replace ' username', ' white') | Set-Content -Path '\\Windows7\C$\test.txt'

Open in new window

I will have to put in a separate  Text file like this:

Windows7    White
PCNT34    JDOck

Open in new window

the first column is the remote computer name and the second column is the string that will replace the second username.

As I stated , the command I pasted above works just fine, it needs to read from a separate text file so that the command will apply to several computers listed on the text file.

Thank you
Watch Question
Most Valuable Expert 2019
Most Valuable Expert 2018
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE