Backup Reg Keys

I am struggling to find a PowerShell way to export reg keys. What I have come up with is creating a function that I have included below and use REG EXPORT. The problem is that I have to code all of that in there.

What I would like to do is be able to use a FOREACH and call all the REG values against REG EXPORT. However I then run into another problem which is providing the name of the key. So I need help finding a way in my foreach (which I can write myself) of just how to

REG EXPORT “HKCU\Software\Microsoft\Internet Explorer\Download” name.reg where as the name would need to be the name of the key that is being exported.

OR maybe there is an even better way and I just don’t know it?

function BACKUPIEREG() {


REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Download" SOFTWARE-MS-IE-DOWNLOAD.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Default HTML Editor" SOFTWARE-MS-IE-DEFHTMLEDIT.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\New Windows" SOFTWARE-MS-IE-NEWWINDOWS.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\TabbedBrowsing" SOFTWARE-MS-IE-TABBROW.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Privacy" SOFTWARE-MS-IE-PRIVACY.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components" SOFTWARE-MS-IE-DESKTOP-COMP.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Main" SOFTWARE-MS-IE-MAIN.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\SearchScopes" SOFTWARE-MS-IE-SEARCHSCOPES.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Settings" SOFTWARE-MS-IE-SETTINGS.REG
REG EXPORT "HKCU\Software\Microsoft\Internet Explorer\Toolbar" SOFTWARE-MS-IE-TOOLBAR.REG 

I would appreciate your help in helping to simplify this process for me.

Do you have a list of keys to export in a text file? If so, yes, you can use a loop to export and name the destination reg file.

Yes they are in a text file. Please help with the loop and naming.

$file = Get-Content \\path\to\regfile.txt
foreach ($line in $file){
$name = $line | Split-Path -Leaf
Start-Process reg -ArgumentList "Export $line \\path\to\$name.reg"

Thank you for your assistance but unfortunately this doesn’t work

When I plug in my values for the $file and the \path\to (which happens to be on the local disk for now)

I see a bunch of CMD boxes open up but there are exported.reg in the desination. Even if I try and change it to just c:\temp$name.reg there is nothing.

No errors at all in the console

Here is my modification

$wfprofile = Join-Path "$ENV:USERPROFILE" -ChildPath "Work Folders\Profile"
$file = Get-Content C:\InternetExplorerREG.txt   (have tried this with ' '  and " " as well as nothing) 
foreach ($line in $file){
$name = $line | Split-Path -Leaf
Start-Process reg -ArgumentList "Export $line $WFPROFILE\$name.reg"  (have tried this just going to c:\temp)

Why not use the registry provider.

You could use something like this:

get-childitem -path 'HKCU:\Software\Microsoft\Internet Explorer' | out-file c:\temp\hkcu.txt

then you can see what is in the text file with type

Hi Thom that works really well, and I can change the .txt to .reg and it outputs great.

Here is what I have working now - Just need to append something else to the name any suggestions for that? Since I am using -leaf it is selecting the last word but that word may not be unique



Both have “Visio” as the last and are therefore over writing each other.

$wfprofile = Join-Path "$ENV:USERPROFILE" -ChildPath "Work Folders\Profile"
New-Item -ItemType Directory -Path $WFPROFILE -Name "IEREG" -Force
$file = Get-Content C:\InternetExplorerREG.txt
foreach ($line in $file){
$name = $line | Split-Path -Leaf
get-childitem | out-file c:\temp\$name.reg 

Whats in your C:\InternetExplorerREG.txt?

Can you give me a sample of what you want the output to look like?