Avatar of D B
D B
Flag for United States of America

asked on 

Using PowerShell to replace text in a set of Files

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.
Powershell

Avatar of undefined
Last Comment
Coralon

8/22/2022 - Mon