-
Notifications
You must be signed in to change notification settings - Fork 14
/
Import-RegistryItem.ps1
98 lines (68 loc) · 2.71 KB
/
Import-RegistryItem.ps1
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<#
.SYNOPSIS
This cmdlet is used to import registry values from a CSV or XML file
.DESCRIPTION
Import registry data from a CSV or XML file
.PARAMETER Path
Define the path(s) to the CSV or XML file containing the registry items to import
.PARAMETER Overwrite
Specify this switch parameter to overwrite any existing registry entries
.EXAMPLE
Import-Registry -Path "$env:USERPROFILE\Downloads\RegBackup.xml"
# This example is used to import the defined registry XML file
.EXAMPLE
Import-Registry -Path "$env:USERPROFILE\Downloads\RegBackup.csv"
# This example is used to import the defined registry CSV file
.NOTES
Author: Robert H. Osborne
Alias: tobor
Contact: rosborne@osbornepro.com
.LINK
https://osbornepro.com
https://btpssecpack.osbornepro.com
https://writeups.osbornepro.com
https://github.com/OsbornePro
https://gitlab.com/tobor88
https://www.powershellgallery.com/profiles/tobor
https://www.hackthebox.eu/profile/52286
https://www.linkedin.com/in/roberthosborne/
https://www.credly.com/users/roberthosborne/badges
.INPUTS
System.String System.Array
.OUTPUTS
System.Management.Automation.PSCustomObject
`Import-RegistryItem` returns a custom object that contains the new property(s).
#>
Function Import-RegistryItem {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
param(
[Parameter(
Position=0,
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$False,
HelpMessage="Define the CSV or XML file path containing the registry items to import." )] # End Parameter
[ValidateScript({
# Unable to verify the registry paths specified
((Test-Path -Path $_) -and (($_ -like "*.csv") -or ($_ -like "*.xml")))
})] # End Parameter
[String[]]$Path,
[Parameter(
Mandatory=$False)] # End Parameter
[Switch][bool]$Overwrite
) # End param
[bool]$Overwrite = $PSBoundParameters.ContainsKey('Overwrite')
If ($Path -like "*.xml") {
$ImportItems = Import-Clixml -Path $Path
} Else {
$ImportItems = Import-Csv -Path $Path
} # End If Else
$ImportItems | ForEach-Object {
If ($PSCmdlet.ShouldProcess(("Overwritting existing registry items. `n$(Get-Content -Path $Path)"),
("Would you like to overwrite these registry items? `n$(Get-Content -Path $Path)"),
"Modifying registry items")
) {
New-ItemProperty -Path $_.Path -Name $_.Name -Value $_.Value -PropertyType $_.Type -Force:$Overwrite
} # End If
} # End ForEach-Object
} # End Function Import-RegistryItem