Powershell regex for replacing text between two strings

后端 未结 2 710
不思量自难忘°
不思量自难忘° 2021-01-17 04:35

I am trying to use a powershell script to change the password between two strings, I am running into two issues.

  1. A complex password seems to break my regex, If
2条回答
  •  悲哀的现实
    2021-01-17 04:40

    This person had a similar issue that I was able to use the regex in my code:

    Hide passwords in string

    I ended up with the following:

    #Set new password in server.xml
    $pass='6QAfD5PmMhWzUxTq1FO1bGJQQXRXu6tizN29h6MRUSI='
    $server_xml=".\server.xml"
    (Get-Content $server_xml) -replace '(?:(?<=keystorePass=")\S+(?="))',("$pass") | Set-Content $server_xml
    

提交回复
热议问题