We help IT Professionals succeed at work.

Read from Text file with Powershell

jskfan used Ask the Experts™
Read from Text file with Powershell

I have a text file that has this data[it represents the name of the device and the user that will logon to it.

Comp1  userA
Comp5 UserX
PC1   UserD
Serv3 User5

Under C: drive of each devices above, there is a text file with a line on it that states:
aaaa bbbbb   -username username

I already have a Powershell script "ChangeString.ps1" that can  replace the second username by the string that I hardcode inside the powershell command. Actually I have to type in the command the Device name and string that will replace the username.
((Get-Content -Path '\\windows7\c$\test.txt' -Raw) -replace ' username', 'white') | Set-Content -Path '\\windows7\C$\test.txt'

you can notice, in the command above, I have to to enter the name of the device (Windows7) and the string "white" to replace the second username.

That's too much when you have so many devices.

I thought that would help if the powershell command can read from a separate text file that has device name and username and do the replacement on each device.

Any Help ?

Thank you
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
What's the difference to your former question: https://www.experts-exchange.com/questions/29166036/replace-a-string-on-a-text-file-on-a-remote-computer.html
Seems like anything you want here is already covered in the old one, or what am I missing?


I see you responded to the previous question

Thank you