Wednesday, October 8, 2008

How to replace strings in multiple files using powershell?

I want to replace string debug="false" with debug="true" for all web.config files in the deployment dir. Here is how to do it:

$pattern ='debug="false"'
$replacement ='debug="true"'
foreach ($file in (gci . -name "web.config" -rec)) {
$text = get-content $file
if ($text -match $pattern) {
$text -replace $pattern, $replacement > $file
}}

http://www.eggheadcafe.com/software/aspnet/29585604/findreplace.aspx

No comments: