Powershell – How to add to a registry key

powershellwindows-registry

I need to create a script to run on a server that I do not have access to.

I need the script to append a string to an existing string value (Type = REG_SZ). The script cannot just replace the entire string with a new value as I don't know what is currently in the entry and I can't lose what is already there.

I was thinking along the lines of regini.exe, but i couldn't figure out how to export, append, import with regini.exe and a batch file. Maybe powershell could do the trick.

Best Answer

Powershell is a solid bet here.

$AppendValue="\Homes"
$RegRoot=Get-ItemProperty "hklm:\software\microsoft\windows\currentversion"
$RegValue=$RegRoot.CommonFilesDir+$AppendValue
Set-ItemProperty -path HKLM:\software\microsoft\windows\Currentversion -Name CommonFilesDir -Value $RegValue

Windows gets twitchy about anything that touches reg or registry.exe, where scripts like the above can run with less complaining.