I have a powershell script that is replacing patterns in a file with the argument passed to the script. I grabbed the algorithm from another site and it works great, except for the fact that when I use anything but a literal string, the pattern isn't replaced.
Here's the original script:
(Get-Content c:\File.txt) |
Foreach-Object { $_ -replace "\*", "@" } |
Set-Content c:\File.txt
Here's my version (basically)
(Get-Content ("c:\File-" + $args[0] + ".txt")) |
Foreach-Object { $_ -replace "\%pattern\%", $args[0] } |
Set-Content ("c:\File-" + $args[0] + ".txt")
The new file is created correctly, and all instances of %pattern% are replaced, but with a blank string, not the string in $args[0]. I am getting hit with a scoping problem for the $args variable?