I am trying to use PowerShell do a simple find and replace in an entire directory of similar files, but the fact that the text I need to replace contains double quotes is causing me issues.
For example, the files have a line like this:
"Enumeration Value": 9
I would like to make that line look like this:
"Enumeration Value": 13
Inside my batch file that is also doing other tasks, I have a powershell command that looks like this:
powershell -Command "(gc '!CURRENT_FILE!') - replace '"Enumeration Value": 9' , '"Enumeration Value": 13' | Set-Content '!CURRENT_FILE!'"
In the example above, CURRENT_FILE
would be the current file that my batch file is processing.
Can anyone help me with why this isn't replacing lines that contain double quotes? I've tried doubling the doubling quotes, escaping the double quotes and probably a few other things that I can't remember right now.
I tried the answer in the thread that this is marked as a duplicate of, but that did not work.
Changing my powershell call to look like this did work:
powershell -Command "(gc '!CURRENT_FILE!') - replace '"\"Enumeration Value\"": 9' , '"\"Enumeration Value\"": 13' | Set-Content '!CURRENT_FILE!'"