PowerShell Script to Find and Replace for all Files with a Specific Extension

Posted by Brandon on Stack Overflow See other posts from Stack Overflow or by Brandon
Published on 2010-05-14T21:36:12Z Indexed on 2010/05/14 22:04 UTC
Read the original article Hit count: 274

Filed under:
|
|
|

I have several configuration files on Windows Server 2008 nested like such:

C:\Projects\Project_1\project1.config

C:\Projects\Project_2\project2.config

In my configuration I need to do a string replace like such:

<add key="Environment" value="Dev"/>

will become:

<add key="Environment" value="Demo"/>

I thought about using batch scripting, but there was no good way to do this, and I heard that with PowerShell scripting you can easily perform this. I have found examples of find/replace, but I was hoping for a way that would traverse all folders within my C:\Projects directory and find any files that end with the '.config' extension. When it finds one, I want it to replace my string values.

Any good resources to find out how to do this or any PowerShell gurus that can offer some insight?

© Stack Overflow or respective owner

Related posts about powershell

Related posts about scripting