I want to search and replace a string in an xml file using PowerShell.I tried this: (gc d:test.xml).replace('1234','xxxx') sc d:test.xmlThis works fine for my test.xml file. The content of my test.xml file is:uehjduehduhfeuf xxxxxxxx hallo '1234'But that file is only for testing. I want to edit a server.xml form my tomcat server in this way and if I'm using exactly the same command mentioned obove I get this error message:Method invocation failed because System.Object doesn't contain amethod named 'replace'.Does anybody know what's the problem?
Oct 28, 2016 One thing that I occasionally forget (and it can take me a while to remember the fix) is some apparently strange behaviour when processing an array. Sometimes array-based methods don't work when there's only one item (or no items!) to be processed. It's all down to PowerShell's automatic type conversion and is pretty easy to.