I'm trying to automate as much as possible at work, and in turn, learn powershell. I just started, so I am struggling a little bit with the following scenario:
I have 1600 config files in ~30 or so sub-dirs. I'd like something that could replace all of a given value with a new value. The problem I'm having is that I cannot figure out how to recursively move between sub-dirs and have the script work. In the meantime, I "hardcoded" the 'cd's to move through the directories, but this is far too clunky to use everywhere.
I appreciate any help.
I have 1600 config files in ~30 or so sub-dirs. I'd like something that could replace all of a given value with a new value. The problem I'm having is that I cannot figure out how to recursively move between sub-dirs and have the script work. In the meantime, I "hardcoded" the 'cd's to move through the directories, but this is far too clunky to use everywhere.
I appreciate any help.
Code:
$old = Read-Host 'What is the value you are looking to replace?'
$new = Read-Host 'What is the new value you want?'
cd 'C:\Path\To\Scripts'
$biotas = Get-ChildItem
ForEach ($biota in $biotas) {
(Get-Content $biota) | ForEach-Object { $_ -replace "$old","$new"} | Set-Content $biota
}