I'm trying replace a few strings within another PowerShell file.
$Source_IP = Read-Host 'Enter source IP'
$Target_IP = Read-Host 'Enter target IP'
By using the following line in another PowerShell script, the file shows as Modified, but the changes don't take effect.
(Get-Content "C:\Solutions.ps1") -replace "$Target_IP = Read-Host 'Enter target IP'", "$Target_IP = '192.168.0.221'" | Set-Content "C:\Solutions.ps1"
Is there a reason why the changes don't take effect?
This is running as an Administrator, on Windows Server 2008, and PowerShell version 2 I believe.
-replaceuse regular expressions.(Get-Content "C:\Solutions.ps1") | ForEach-Object{$_.Replace($Source_IP,$Target_IP)} | Set-Content "C:\Solutions.ps1"? Just simple matching no regex.