need a bit of help here with multi line replacement and wildcards.
Long story short, I am writing a script to update our systems from Tomcat 7 to Tomcat 9, however there are some significant server.xml changes needed and the script needs to be written to work with wildcards to replace the site.bin name in the connector info.
Current script saves old Tomcat 7 server.xml file and relevant part is below: `
<Connector
port="8443" maxThreads="150"
scheme="https" secure="true" SSLEnabled="true"
enableLookups="true" disableUploadTimeout="true"
keystoreFile="/webapps/site.bin" keystorePass="password"
clientAuth="false" sslProtocol="TLS"/>
`
New Tomcat 9 server xml below that needs to be replaced with the above:
`
<Connector port="8443" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
` I tried using the below code setting $oldCode as an array of the tomcat 9 connector info and $newCode as an array of the Tomcat 7 connector info, but it's not making a single change so I assume it's not finding that string in the replace command:
$oldCode = @"
<Connector port="8443" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
"@
$NewCode = @"
<Connector
port="8443" maxThreads="150"
scheme="https" secure="true" SSLEnabled="true"
enableLookups="true" disableUploadTimeout="true"
keystoreFile="/webapps/site.bin" keystorePass="password"
clientAuth="false" sslProtocol="TLS"/>
"@
(get-content -raw server.xml) -replace $oldCode, $NewCode | set-content Server-New.xml
What is the best way to replace the multi line array while accounting for variations in the "site.bin" syntax that will change from system to system?
Really lost on this one as I find it easy to replace single lines, or specific lines, but multiple lines with wildcards and specific xml formatting seems above my experience level at this time.