# Backup Reg Keys

This topic contains 7 replies, has 3 voices, and was last updated by  thom schumacher 2 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
• Author
Posts
• #47651

crashrebootrepeat
Participant

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() {

#BACKUP IE REGKEYS

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.

#47771

random commandline
Participant

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.

#47789

crashrebootrepeat
Participant

#47804

random commandline
Participant
$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" }  #47826 crashrebootrepeat Participant 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) }  #47882 thom schumacher Participant 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 #47936 crashrebootrepeat Participant 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 IE: HKCU:\SOFTWARE\MICROSOFT\OFFICE\VISIO HKCU:\SOFTWARE\MICROSOFT\OFFICE\16\VISIO 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
}

#48468

thom schumacher
Participant