Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using PowerShell need assistance with replace text in multiple fil

1 view
Skip to first unread message

DanO

unread,
Jul 9, 2008, 10:48:01 AM7/9/08
to
Hello,

I am trying to change(using Power Shell) errors in 20 to 50 *.ini files and
the logic for the loop escapes me.

Thank you in advance,
--
Dan O

Alex

unread,
Sep 28, 2008, 10:47:01 PM9/28/08
to
I was having the same problem but ultimately was able to figure it out. See
below example from the command line:

From the location of where the .ini files are, type in the following:
(Note: the 'for' loop is one long line, just cut/copy and paste into the PS
prompt)

$filename = Get-ChildItem -name *.ini
$i = 0

for ($i = 0; $i -le ($filename.length - 1); $i++) {
(Get-Content $filename[$i]) | ForEach-Object {$_ -replace "[old text]",
"[new text]"} | Set-Content $filename[$i]
}

It doesn't output any text but the functionality of it should do exactly
what you are looking for. Just be sure to replace [old text] & [new text]
with your text.

Enjoy!

- Alex

0 new messages