I am finding/replacing words in Powershell. I am curious about the order of replacement.
Want to have it Sequentially replace Test1 with Test2, and Then replace certain string combination of Test2 with Test3 (see below).
1) Just curious if its safe writing code below? Or Does Powershell run things simultaneously, thus breaking my Required Sequence replacement pattern?
It seems to be work, just want to be 100% sure. Otherwise, I can write another foreach loop, after the first replacement is complete.
2) Also, do I need the pipe delimiters below? Not sure what they do, inheriting this script from previous programmer, attempting to google and research powershell.
#Replace words in file
$TestFiles = Get-ChildItem $DBContextDestination *.cs -rec
foreach ($file in $TestFiles )
{
(Get-Content $file.PSPath) |
Foreach-Object { $_ -replace "abcd", "1234" } |
Foreach-Object { $_ -replace "Test1;", "Test2" } |
Foreach-Object { $_ -replace "Class Test2 Object", "Class Test3 Object" } |
Set-Content -Encoding UTF8 $file.PSPath
}