Reputation: 1
I'm trying to use set-itemproperty to add an item to: HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\Installation Sources
$InstallationSources = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" -Name "Installation Sources"
$test = $InstallationSources."Installation Sources" + "C:\Test\I386"
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" -Name "Installation Sources" "$test"
I can echo $test and it looks fine, several lines of paths with my addition at the end. But when I actually use set-itempproperty, it squishes everything into one line, which doesn't work. Each path needs to have its own line. Even manually added newlines aren't passed in (ie: "`nC:\Test\I386"). Ideas?
Thanks
Upvotes: 0
Views: 2524
Reputation: 202072
If you want to preserve newlines then make sure the registry value is of type MultiString otherwise the registry won't allow the newlines AFAICT e.g.:
PS> New-ItemProperty hkcu:\ -Name bar -PropertyType MultiString
PS> Set-ItemProperty hkcu:\ -Name bar -Value "contents`r`nmore contents"
PS> Get-ItemProperty hkcu:\ -Name bar
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\
PSParentPath :
PSChildName : HKEY_CURRENT_USER
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
bar : {contents
more contents}
Upvotes: 1
Reputation: 29480
$test is an array of strings and powershell is automatically joining them together for you when you say:
"$test"
You need to do the join yourself, providing the correct separator character. i.e.:
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup" -Name "Installation Sources" ($test -join "`n")
Upvotes: 0