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
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.
((Get-Content -path '\\windows7\c$\test.txt' -Raw) -replace 'username','white') | Set-Content -Path '\\windows7\C$\test.txt'