I'm trying to edit a text file from PowerHhell, following the refresh of a directory.
Trying to Get-Content from the target location where the source dbconnecthost is what we're searching for.
We then want to replace with the target information and Set-Content. These variables are being pulled from another .ps1 file.
The below is what I'm attempting to use.
function ReplaceDBhost {
Get-Content ("$TargetLocation\Data\config.txt") | Foreach-Object {
$_ -replace ('^dbconnecthost=' + '$SourceDBConnectHost'), ('dbconnecthost=' + '$TargetDBConnectHost' )
} | Set-Content ("$TargetLocation\Data\config.txt")
}
The problem is, I'm not getting any changes when I run this. Any help is greatly appreciated.