Reputation: 156
I would like to export multiple registry keys to the same .reg file. Every suggestion I've seen shows to use reg /e [key name] filename.reg, but I have a list of 4-5 registry entries I want to export and doing it this way will overwrite it each time. What I want is something like:
So that each registry key is appended to the same .reg file, not overwritten each time. How can I do this?
Upvotes: 5
Views: 22062
Reputation: 1
I was getting errors when using Ansgar solution but I was able to get it to work by modifying it a little. When the set-content is used the first time the add-content wouldn't work because the file was in use.
$keys = 'HKLM\Software\Test\ABC', 'HKLM\Software\ABC\123', ...
$tempFolder = $temp_cache
$outputFile = "C:\path\to\merged.reg"
$keys | % {
$i++
& reg export $_ "$tempFolder\$i.reg" /y
}
Get-Content "$tempFolder\*.reg" | Set-Content $outputFile
Upvotes: -1
Reputation: 200193
The simplest way would be to export each key individually, and then merge the resulting files:
$keys = 'HKLM\Software\Test\ABC', 'HKLM\Software\ABC\123', ...
$tempFolder = 'C:\temp\folder'
$outputFile = 'C:\path\to\merged.reg'
$keys | % {
$i++
& reg export $_ "$tempFolder\$i.reg"
}
'Windows Registry Editor Version 5.00' | Set-Content $outputFile
Get-Content "$tempFolder\*.reg" | ? {
$_ -ne 'Windows Registry Editor Version 5.00'
} | Add-Content $outputFile
Upvotes: 10