locked
modify value data multi-string for regkey RRS feed

  • Question

  • Hello,

    I am trying to add a value to a multi-string in a registry key.

    I am using the set-itemproperty command but when I use that it wipes all the other values out in the string and inputs the one I wanted added to the string.

    How do I keep the other value settings whilst adding the new one?

    Thanks

    Stephen

    Monday, October 22, 2018 2:14 PM

All replies

  • You should learn how to use an internet search engine!

    https://powershell.org/forums/topic/working-with-multistring-registry-property/

    http://community.idera.com/powershell/ask_the_experts/f/powershell_for_windows-12/6996/add-a-new-multi-string-value-to-windows-registry

    These are the first 2 hits when I search for "Powershell modify value data multi-string for regkey"!!


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Monday, October 22, 2018 2:30 PM
  • What a good idea.  I wish I had thought of that!
    Monday, October 22, 2018 2:35 PM
  • Those links aren't great.  Also the -type parameter isn't documented.  This example adds 'there' to 'hi' in a multistring registry entry.

    New-Item hkcu:\key1 
    Set-ItemProperty hkcu:\key1 multistring1 hi -Type MultiString
    $a = get-itemproperty hkcu:\key1 multistring1
    $newstringarray = $a.multistring1 + 'there'
    Set-ItemProperty hkcu:\key1 multistring1 $newstringarray -Type MultiString

    • Edited by JS2010 Tuesday, October 23, 2018 2:31 AM
    Monday, October 22, 2018 2:36 PM
  • What a good idea.  I wish I had thought of that!
    So why didn't you do it? It took me 20 seconds.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Monday, October 22, 2018 2:55 PM
  • Hi,

    Thanks for your question.

    Please search on the Internet before posting your problem.

    Also you can use WMI to solve your problem.

    Refer the link below:

    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/regprov/setmultistringvalue-method-in-class-stdregprov

    http://community.idera.com/powershell/ask_the_experts/f/powershell_for_windows-12/6996/add-a-new-multi-string-value-to-windows-registry

    Best Regards,

    Lee


    Just do it.

    Tuesday, October 23, 2018 2:01 AM
  • Those links aren't great.  Also the -type parameter isn't documented.  This example adds 'there' to 'hi' in a multistring registry entry.

    New-Item hkcu:\key1 
    Set-ItemProperty hkcu:\key1 multistring1 hi -Type MultiString
    $a = get-itemproperty hkcu:\key1 multistring1
    $newstringarray = $a.multistring1 + 'there'
    Set-ItemProperty hkcu:\key1 multistring1 $newstringarray -Type MultiString


    "Type" is not a parameter of "Set-ItemProperty"

    \_(ツ)_/

    Tuesday, October 23, 2018 6:42 AM
  • Hi,

    Thanks for your question.

    Please search on the Internet before posting your problem.

    Also you can use WMI to solve your problem.

    Refer the link below:

    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/regprov/setmultistringvalue-method-in-class-stdregprov

    http://community.idera.com/powershell/ask_the_experts/f/powershell_for_windows-12/6996/add-a-new-multi-string-value-to-windows-registry

    Best Regards,

    Lee


    Just do it.

    Please read the question more carefully.  Your answers have nothing to do with the question.


    \_(ツ)_/

    Tuesday, October 23, 2018 6:43 AM
  • I did search the internet and was having a few issues hence why I then reached out to the forums.
    Tuesday, October 23, 2018 11:25 AM
  • Thanks for getting back to me. 

    I appreciate the help instead of some smart unhelpful comment regarding search engines!

    I managed to get this working (finally) which resolved my issue.

    #get the MultiLine String Array from the registry

    $regArry = (Get-Itemproperty "HKLM:\SOFTWARE\Microsoft\AppV\Subsystem\VirtualRegistry" -name "PassThroughPaths").("PassThroughPaths")

     

    #Create a new String Array

    [String[]]$tempArry = @()

     

    #Create an ArrayList from the Registry Array so I can edit it

    $tempArryList = New-Object System.Collections.Arraylist(,$regArry)

     

     

    <# remove an entry from the list

    if ( $tempArryList -contains "EnPasFlt" )

    {  

        $tempArryList.Remove("EnPasFlt")

    }

    #>

     

    <#

    Add an entry

    if ( !($tempArryList -contains "VB and VBA Program Settings"))

    {

    write-host "File Exists"}

    ELSE

    {

    #>

     

     

    $tempArryList.Add("HKEY_CURRENT_USER\SOFTWARE\VB and VBA Program Settings")

     

     

    foreach($i in $tempArryList) { $tempArry += $i + "`r`n"}

     

     

    # Remove the old Array from the Registry

    (Remove-ItemProperty "HKLM:\SOFTWARE\Microsoft\AppV\Subsystem\VirtualRegistry" -name "PassThroughPaths").("PassThroughPaths")

     

    # Add the new one

    New-itemproperty "HKLM:\SOFTWARE\Microsoft\AppV\Subsystem\VirtualRegistry" -name "PassThroughPaths" -PropertyType MultiString -Value "$tempArry" 

    Tuesday, October 23, 2018 11:29 AM
  • Those links aren't great.  Also the -type parameter isn't documented.  This example adds 'there' to 'hi' in a multistring registry entry.

    New-Item hkcu:\key1 
    Set-ItemProperty hkcu:\key1 multistring1 hi -Type MultiString
    $a = get-itemproperty hkcu:\key1 multistring1
    $newstringarray = $a.multistring1 + 'there'
    Set-ItemProperty hkcu:\key1 multistring1 $newstringarray -Type MultiString


    "Type" is not a parameter of "Set-ItemProperty"

    \_(ツ)_/

    You keep saying this.  And yet command line completion works with the -type parameter, and my example works without error.
    Tuesday, October 23, 2018 12:12 PM
  • You keep saying this.  And yet command line completion works with the -type parameter, and my example works without error.
    Hmmm ... not in my environment. ;-)  When you use Set-ItemProperty the item already exists and has a type. So no need to set a type - you simply change the value.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Tuesday, October 23, 2018 12:18 PM
    Tuesday, October 23, 2018 12:17 PM
  • Thanks for getting back to me. 

    I appreciate the help instead of some smart unhelpful comment regarding search engines!

    I managed to get this working (finally) which resolved my issue.

    Please do not post colorized code. Use the code posting tool provided.


    \_(ツ)_/

    Tuesday, October 23, 2018 1:36 PM
  • Not "Type" here in the latest version of PowerShell:

    NAME
        Set-ItemProperty
    
    SYNOPSIS
        Creates or changes the value of a property of an item.
    
    
    SYNTAX
        Set-ItemProperty [-Path] <String[]> [-Confirm] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filt
        -InputObject <PSObject> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]
    
        Set-ItemProperty [-Confirm] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Forc
        <PSObject> -LiteralPath <String[]> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]
    
        Set-ItemProperty [-Name] <String> [-Value] <Object> [-Confirm] [-Credential <PSCredential>] [-Exclude <S
        [-Include <String[]>] -LiteralPath <String[]> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters
    
        Set-ItemProperty [-Path] <String[]> [-Name] <String> [-Value] <Object> [-Confirm] [-Credential <PSCreden
        <String>] [-Force] [-Include <String[]>] [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]
    
    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-itemproperty?view=powershell-5.1


    \_(ツ)_/

    Tuesday, October 23, 2018 1:41 PM
  • Not "Type" here in the latest version of PowerShell:

    NAME
        Set-ItemProperty
    
    SYNOPSIS
        Creates or changes the value of a property of an item.
    
    
    SYNTAX
        Set-ItemProperty [-Path] <String[]> [-Confirm] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filt
        -InputObject <PSObject> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]
    
        Set-ItemProperty [-Confirm] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Forc
        <PSObject> -LiteralPath <String[]> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]
    
        Set-ItemProperty [-Name] <String> [-Value] <Object> [-Confirm] [-Credential <PSCredential>] [-Exclude <S
        [-Include <String[]>] -LiteralPath <String[]> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters
    
        Set-ItemProperty [-Path] <String[]> [-Name] <String> [-Value] <Object> [-Confirm] [-Credential <PSCreden
        <String>] [-Force] [-Include <String[]>] [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]
    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-itemproperty?view=powershell-5.1


    \_(ツ)_/

    I'm glad we agree that it's not property documented.

    Tuesday, October 23, 2018 1:51 PM
  • You keep saying this.  And yet command line completion works with the -type parameter, and my example works without error.

    Hmmm ... not in my environment. ;-)  When you use Set-ItemProperty the item already exists and has a type. So no need to set a type - you simply change the value.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    What is your environment?
    Tuesday, October 23, 2018 1:56 PM
  • In any environment I have tried "Type" does not auto-complete.

    Yes it is undocumented and works in a very flakey way.  It is one of the weird PS flukes.


    \_(ツ)_/

    Tuesday, October 23, 2018 2:03 PM
  • What is your environment?

    Windows 7 SP1  /  Windows 10 1709  /  Windows Server 2012  /  Windows  Server 2012R2  /  Windows Server 2016

    On all these systems I don't have a -Type parameter for Set-Itemproperty - do you?

    It wouldn't make sense to me anyway as I wrote before. When you set (change) an itemproperty it aleady has a type. So the parameter does make sense for New-ItemProperty but not for Set-ItemProperty.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, October 23, 2018 2:05 PM
  • Here is the solution to help others understand how easy this is.

    $p = (Get-ItemProperty HKCU:\Software\Test).MS_Test
    $p += 'four'
    Set-ItemProperty HKCU:\Software\Test -Name MS_Test -Value $p -Type Multistring

    There is no need to play with arraylists or joining or any other strange things.  Just get the array and add a value.

    To conditionally add just test and add;

    $p = (Get-ItemProperty HKCU:\Software\Test).MS_Test
    if($p -notcontains 'four'){$p += 'four'}
    Set-ItemProperty HKCU:\Software\Test -Name MS_Test -Value $p -Type Multistring

    In this case the "Type" is required or the value will be seen as a single string and the array will be lost.

    Thankyou JS2010 for insisting on using this.


    \_(ツ)_/



    • Edited by jrv Tuesday, October 23, 2018 2:09 PM
    • Proposed as answer by jrv Tuesday, October 23, 2018 2:10 PM
    Tuesday, October 23, 2018 2:07 PM
  • What is your environment?

    Windows 7 SP1  /  Windows 10 1709  /  Windows Server 2012  /  Windows  Server 2012R2  /  Windows Server 2016

    On all these systems I don't have a -Type parameter for Set-Itemproperty - do you?

    It wouldn't make sense to me anyway as I wrote before. When you set (change) an itemproperty it aleady has a type. So the parameter does make sense for New-ItemProperty but not for Set-ItemProperty.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Set-ItemProperty can also be used to create a value and, if we don't use type, MS values will be converted to simple strings.

    This is another MS "Cluster Freakout" that helps to keep everyone confused. This is likely because many junior programmers at MS don't understand the registry or how to define a consistent API.


    \_(ツ)_/

    Tuesday, October 23, 2018 2:14 PM
  • What is your environment?

    Windows 7 SP1  /  Windows 10 1709  /  Windows Server 2012  /  Windows  Server 2012R2  /  Windows Server 2016

    On all these systems I don't have a -Type parameter for Set-Itemproperty - do you?

    It wouldn't make sense to me anyway as I wrote before. When you set (change) an itemproperty it aleady has a type. So the parameter does make sense for New-ItemProperty but not for Set-ItemProperty.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    It works on all the systems I have access to.  But I have to type a path located in the registry first.
    Tuesday, October 23, 2018 2:15 PM
  • Set-ItemProperty can also be used to create a value and, ...
    I didn't know that .... thanks.  :-)

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, October 23, 2018 2:19 PM
  • What is your environment?

    Windows 7 SP1  /  Windows 10 1709  /  Windows Server 2012  /  Windows  Server 2012R2  /  Windows Server 2016

    On all these systems I don't have a -Type parameter for Set-Itemproperty - do you?

    It wouldn't make sense to me anyway as I wrote before. When you set (change) an itemproperty it aleady has a type. So the parameter does make sense for New-ItemProperty but not for Set-ItemProperty.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    It works on all the systems I have access to.  But I have to type a path located in the registry first.

    Ahh - that is the trick.

    \_(ツ)_/

    Tuesday, October 23, 2018 2:20 PM
  • It works on all the systems I have access to.  But I have to type a path located in the registry first.
    Ahh ...  ok ... this way it works for me too ...  wow ...  I'm confused ;-)  ...  OK, I'm going to call it a day. :-D

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, October 23, 2018 2:24 PM