Avatar of jskfan
jskfan
Flag for Cyprus

asked on 

Find and Replace string using Powershell

Find and Replace string using Powershell

I have  a file Test.txt on a remote computer  named Windows7

the Test.txt  has a line:
aaaa bbbbb   -username  username

Open in new window


I would like to replace the second username with a string 'white'. the command line below works fine, however it is replacing both -username and username with 'white', I need just the second one replaced.
Thank you

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

Open in new window

PowershellScripting Languages

Avatar of undefined
Last Comment
jskfan

8/22/2022 - Mon