Powershell Export Multiple Keys To One .reg File

此生再无相见时 提交于 2020-03-03 05:43:40

问题


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:

  • Export HKLM\Software\Test\ABC RegFile.reg
  • Export HKLM\Software\ABC\123 RegFile.reg
  • Export HKLM\Software\XYZ\Lala RegFile.reg

So that each registry key is appended to the same .reg file, not overwritten each time. How can I do this?


回答1:


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


来源:https://stackoverflow.com/questions/28076128/powershell-export-multiple-keys-to-one-reg-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!