$filePath = 'c:\Users\MyName\Desktop\PLC_Comm_D13_VCL\uMain.pas' $lines = Get-Content $filePath -Encoding Default for ($i = 0; $i -lt $lines.Count; $i++) { if ($lines[$i] -match 'valve01_ctrl_shm_addr = 24;') { $lines[$i] = ' valve01_ctrl_shm_addr = 35;' } elseif ($lines[$i] -match 'valve01_ctrlSts_shm_addr = 35;') { $lines[$i] = ' valve01_ctrlSts_shm_addr = 24;' } elseif ($lines[$i] -match '19 \+ DONum, 1\)') { $lines[$i] = $lines[$i] -replace '19', '34' } elseif ($lines[$i] -match '19 \+ DONum, 0\);') { $lines[$i] = $lines[$i] -replace '19', '34' } } Set-Content -Path $filePath -Value $lines -Encoding Default Write-Host 'Done.'