copy the below sample to a file called SetRegKeyEx1.ps1
then run it as follows ( the script adds a testkey to your registry – change the key values as needed )
powershell.exe -ExecutionPolicy RemoteSigned .\SetRegKeyEx1.ps1
#
[string]$script:psMultiSz
if (!(Test-Path HKLM:\System\CurrentControlSet\Newkey)) { md HKLM:\System\CurrentControlSet\Newkey }
New-ItemProperty HKLM:\System\CurrentControlSet\Newkey TestValue -value “One”,”Two”,”Three” -propertyType Multistring
# ///////// Get the main key /////////////////////////////////////
$key = Get-Item HKLM:\System\CurrentControlSet\NewKey
$keytwo = Get-ItemProperty $key.PSPath “TestValue”
$psMultiSz = $Keytwo.(“TestValue”)
Write-Host “this is current value of TestValue-> $psMultiSz`n”
# ///////// Add a new value to the multistring value /////////////////////////////////////
$psMultiSz += “four”
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\NewKey -name “TestValue” -Value $psMultiSz -Type MultiString
Write-Host “new value added to TestValue key`n”
# ///////// Retrieve the new value /////////////////////////////////////
$key = Get-Item HKLM:\System\CurrentControlSet\NewKey
$keytwo = Get-ItemProperty $key.PSPath “TestValue”
$psMultiSz = $Keytwo.(“TestValue”)
write-host “this is the new value of TestValue -> $psMultiSz`n”
Follow me on Twitter
Sorry, the comment form is closed at this time.