Author Posts

October 8, 2013 at 8:43 am


I have not been able to find an example of using Powershell to edit/create MultiString registry entries.
As an example, I'm working with automating configuration of Tomcat, running as a windows service (ick).

Anyway, I've tried to create a string

$a=@("`n`r -Dcatalina.base=D:\servers\vci003`n`r -Dcatalina.home=D:\tomcat\apache-tomcat-7.0.42`n`r -Djava.endorsed.dirs=D:\tomcat\apache-tomcat-7.0.42\endorsed`n`r\servers\vci003\temp`n`r -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager`n`r -Djava.util.logging.config.file=D:\servers\vci003\conf\`n`r -XX:+PrintGCTimeStamps`n`r -XX:+PrintGCDetails`n`r -verbose:gc`n`r -Xloggc:D:\servers\vci003\logs\gc.log`n`r")

And then insert using

new-ItmProperty "hklm:SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\vci003\Parameters\Java" -Type MultiString  -PSProperty optionTest -Value $a

It appears to create it correctly, however when I open the registry key in RegEdit, the contents display as one continuous string, instead of each property being on a different line.

October 8, 2013 at 8:55 am

Right now, you're create a one-item array that is a string, and that string contains carriage return and linefeed characters, correct?

Have you tried creating an array of strings instead?

$a = @("Setting one","Setting 2","Setting 3")

October 8, 2013 at 8:59 am

In your example, $a is a one-element array containing a string that happens to have embedded newline / carriage return characters. What you actually need to send is a multi-element array of strings, like this:

    " -Dcatalina.base=D:\servers\vci003",
    " -Dcatalina.home=D:\tomcat\apache-tomcat-7.0.42",
    " -Djava.endorsed.dirs=D:\tomcat\apache-tomcat-7.0.42\endorsed",
    " -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager",
    " -Djava.util.logging.config.file=D:\servers\vci003\conf\",
    " -XX:+PrintGCTimeStamps",
    " -XX:+PrintGCDetails",
    " -verbose:gc",
    " -Xloggc:D:\servers\vci003\logs\gc.log"

New-ItemProperty -Path "hklm:SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\vci003\Parameters\Java" -PropertyType MultiString -Name optionTest -Value $a

October 8, 2013 at 9:23 am

Thank you both, that did it!