powershell on command line replace double quoted text

Hi all

I have a file containg (multiple) xml tags that contain the attribute type=“ABC”. The ABC needs to be replaced by XYZ.

I have tried to use the below (escape with backtick, as it seems to be the standard in powershell) and the variation of it by escaping the double quotes with the backslash (I’m basically a pure C programmer).

 powershell -command "(gc %rootdir%\directory\file3.xml) -replace 'TYPE=`"ABC`"','TYPE=`"XYZ`"' | Out-File %rootdir%\directory\file.xml" -encoding ASCII

I eventually tried escaping the double quote with another double quote and that worked. The question is where I can read up on escaping in powershell or if somebody can explain why only the escaping the double quote with a double quote worked.

Thanks in advance

Here you go: about Quoting Rules - PowerShell | Microsoft Docs

You may read the free Powershell cookbook about working with XML files. I’d recommend to treat an XML file not like plain text. :wink:

Thanks people for the replies.

I’m aware that I will probably be better of using the XML approach but this is an attempt at a quick and dirty hack to fix a tool-chain after requirements for the output files changed.