Assuming you have defined $ FilePath, $ user and / or a computer elsewhere, try something like this.
$files = Get-ChildItem $FilePath\*.txt foreach ($file in $files) { (Get-Content $file) | Foreach-Object { $content = $_ -replace "User:", "User: $user" ; $content -replace "Computer:", "Computer: $computer" } | Set-Content $file }
You can use ; to distinguish between additional commands inside the Foreach-Object , for example, if you want to have separate commands for your username and computer. If you do not attach the Get-Content cmdlet with a parenthesis, you will receive an error message because this process will still have the $ file when Set-Content tries to use it.
Also note that using Powershell, double-quoted strings will evaluate variables, so you can put $ user in a string to do something like "User: $user" if you wish.
source share