troubleshooting Question

Using PowerShell to replace text in a set of Files

Avatar of D B
D BFlag for United States of America asked on
Powershell
3 Comments1 Solution39 ViewsLast Modified:
I need a PowerShell script to replace A with B in multiple files. However, A and B are coming in from a separate file and contain comma-delimited pairs. A represents what to replace and B is what to replace it with.

The files to search and replace are all in a specific directory, and all same filetype (e.g. *.SQL).

So, if the file containing the match and replace pairs contains:
Apples,Oranges
Cows,Horses
Yellow,Blue

And I have 5 files to search, then for each file I would replace Apples with Oranges, Cows with Horses and Yellow with Blue.

Note: The comma-delimited pair file could contain up to 200 pairs.

I've gotten to where I'm reading the contents of the comma-delimited pairs file into an array but I'm fidgeting with proper nesting of all my loops and how to replace each pair within each file.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros