Hello everybody,
I have a web based application that our customers use and I’m trying to create a script to migrate the configuration files from one server to a new server. So far I’ve been able to install the application onto the new server with a clean installation and copy the configuration files over from the old server. The last thing I need to do is replace all instances of the hostname, the IP address, and the file path (assuming it’s on a different drive letter than the original server. The configuration files are all in on main directory folder but it contains about 70 sub folders. There are also many different file types involved (.xml, .config, .txt). I need help in figuring out how to get it to search all the sub folders. I’ve managed to figure out how to replace one variable at a time, but it’s only changing it into the main directory, not in the subfolders. Any suggestions on how to get this to search and replace in the subfolders? Any suggestions on how to get this to replace all three variables (if they exist in that file) at the same time, as opposed to searching the entire directory three times? This is what I’ve come up with so far:
$InputFiles = Get-Item "E:\Test\*.*" $OldString = 'OLDHOSTNAME' $NewString = 'NEWHOSTNAME' $InputFiles | ForEach { (Get-Content -Path $_.FullName).Replace($OldString,$NewString) | Set-Content -Path $_.FullName }