I’m new to this forum, but have been searching for some advice/answers on something I am trying to implement.
I have files (web.config or connections.config) that contain the database connection strings with the password in clear text.
I need to scrape the files in search of every and any instance of the password and replace with XXXXX for example.
My problem is that there are many ways to define the connection (in the XML web.config file), so instead of trying to use the XML tags, I thought it might be possible to use regex to do what I need?
In short, I would need to find any occurrence of password=gdgdgdgdgdg; or pwd=hhdhdhdhd" or any combination of Password/pwd/Pwd and with spaces before and after the equals signs etc.
So I would search for a string (one example would be: ;password=, then replace everything up to next colon (
So there would be a lot of strings ( ;password= or ;password = or ;PWD= or ;Pwd = ) etc.
but what I am hoping is possible is that once it finds all and any of the strings, it can replace everything up to the next occurence of a colon?
I was able to test on regex101.com using this:
That was finding the text after the equals sign and before the next colon in the group2 match
However, I could not figure out how to do that in powershell regex. I could use the -match to find password=, but I couldn’t work out how to make powershell find the string and then the text after the string Before the next colon occurence.
Sorry, if I am not explaining it clearly - I hope someone can give me some advice or sample powershell code to find that string and then replace everything after the string before the colon
Any advice would be really appreciated!