Working with MultiString registry property

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Michael Craig Michael Craig 3 years, 8 months ago.

  • Author
    Posts
  • #10608
    Profile photo of Michael Craig
    Michael Craig
    Participant

    Hello,

    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 -Djava.io.tmpdir=D:\servers\vci003\temp`n`r -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager`n`r -Djava.util.logging.config.file=D:\servers\vci003\conf\logging.properties`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.

  • #10610
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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")

  • #10611
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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:

    $a=@(
        " -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.io.tmpdir=D:\servers\vci003\temp",
        " -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager",
        " -Djava.util.logging.config.file=D:\servers\vci003\conf\logging.properties",
        " -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
    
  • #10612
    Profile photo of Michael Craig
    Michael Craig
    Participant

    Thank you both, that did it!

You must be logged in to reply to this topic.