Ansible Replace a value in a File

I am trying to Replace a String in an xml file . but using win_lineinfile module only the last occurence of it is replaced
how can i replace a String in all occurences .
One Solution i found is tro run from powershell
(Get-Content C:\Program Files\dd\config.xml).replace(‘ToReplace’,‘replaced’) | Set-Content C:\Program Files\dd\config.xml

But when i try to use the same powershell from playbook
win_shell: (Get-Content C:\Program Files\dd\config.xml).replace(‘ToReplace’,‘sss’) | Set-Content C:\Program Files\dd\config.xml

Its executing but chnages are not happening ., Any solutions please

Hi

Search and replacing of strings in XML tends to be very fragile, as
you experience.
Adding win_shell powershell and pipes will only make that worse.

If your desired changes allow, you should use the dedicated XML module:

https://docs.ansible.com/ansible/latest/modules/xml_module.html