-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExport-Registry.ps1
More file actions
81 lines (66 loc) · 2.43 KB
/
Copy pathExport-Registry.ps1
File metadata and controls
81 lines (66 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<#
.Synopsis
Exports registry keys into *.reg files.
.Description
Exports registry keys into reg files without using reg.exe, and optionally filters the results.
.Parameter RegKey
The path to the registry key you want to export.
.Parameter Like
The -Like filter to use to filter exported keys.
Default '*'
.Parameter OutFile
The path to the output *.reg file you want to create. This will overwrite the file without warning.
.Example
# Export a *.reg file containing all keys under 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths' that match the wildcard string '*in*'.
Export-Registry -RegKey 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths' -Like *in* -OutFile out.reg
#>
# Authot: mjmeans 2023-06-27
#
# Change log
# 2023-06-28: mjmeans
# Added ability to -Verbose
# Added support for binary values
# Removed $file parameter. Just pipe output to Out-File 'filename.reg'
# 2023-06-29: mjmeans
# Wrap binary key=value output to match reg export format
# 2023-07-06: mjmeans
# Added Write-Log
# Added support for (default) @
# Removed the ability to invoke the script on a remove computer
#
# TO DO
# Add remote option back in
# Verify that $RegKey is an actual registry key instead of something else
#
# TEST
# Import test file '_Test_Reg-Export.reg' into registry
# PV> .\Export-Registry.ps1 -RegKey 'HKLM:\SOFTWARE\_Test' -Like '*Reg-Export*' -OutFile 'out.reg' -Verbose
# Compare the '_Test_Reg-Export.reg' to the 'out.reg' file
[CmdletBinding()]
Param (
[string]$RegKey = $(throw '-RegKey is required'),
[string]$Like = '*',
[string]$OutFile = $(throw '-OutFile is required')
)
## Includes
. .\Write-Log.ps1
. .\Format-RegExport.ps1
## Constants
$crlf = "`r`n"
## Verify before run
if (!(Test-Path -Path $RegKey -PathType Container))
{
Write-Log -Level ERROR "PATH_NOT_FOUND: `"$RegKey`""
Write-Log "The registry key specified by -RegKey <key> must exist."
exit
}
$key = Get-Item $RegKey
$search = Join-Path $key $Like
Write-Log "Searching $search"
Write-Output 'Windows Registry Editor Version 5.00' | Out-File $OutFile -Encoding unicode
$keys = Get-ChildItem $Regkey -Recurse -Verbose | Where-Object {($_.Name -like $search)}
foreach ($k in $keys) {
Format-RegExport -InputObject $k | Out-File $OutFile -Append -Encoding unicode
}
Write-Output "" | Out-File $OutFile -Append -Encoding unicode
Write-Log "Completed"