-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunScript - Registry Key Check-Change.ps1
More file actions
64 lines (60 loc) · 2.88 KB
/
RunScript - Registry Key Check-Change.ps1
File metadata and controls
64 lines (60 loc) · 2.88 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
# Registry Key Check-Change
# Gets Value of RegKey and Changes (if select) for both System or User hives
# Varriables...
# Key: Software\Policies\Microsoft\MicrosoftEdge\Internet Settings
# Name: ProvisionedHomePages
# Value:
# Action: Check, Change
# Hive: HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_CURRENT_USER
# Type: DWord, String, ExpandString, QWord, Binary
Param(
[Parameter(Mandatory=$True)]
[string]$Key,
[Parameter(Mandatory=$True)]
[string]$Name,
[Parameter(Mandatory=$True)]
[string]$Action,
[Parameter(Mandatory=$True)]
[string]$Hive,
[Parameter(Mandatory=$False)]
[string]$Value,
[Parameter(Mandatory=$False)]
[string]$Type
)
Try {
# Normalize User Input
$Keys = @()
IF ($Hive -eq "HKEY_LOCAL_MACHINE") {
$Keys = [PSCustomObject]@{Path = "Registry::" + $Hive + "\" + $Key}
} ElseIf ($Hive -eq "HKEY_CLASSES_ROOT") {
$Keys = [PSCustomObject]@{Path = "Registry::" + $Hive + "\" + $Key}
} ElseIf ($Hive -eq "HKEY_CURRENT_USER") {
$Keys += (Get-ChildItem Registry::HKEY_USERS -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' }).PSChildName |
Select-Object @{N="Path";E={"Registry::HKEY_USERS\" + $_ + "\" + $Key}},@{N="SID";E={$_}},
@{N="User";E={((Get-ItemProperty ("Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" + $_ ) -ErrorAction SilentlyContinue).ProfileImagePath -Split "\\")[-1]}}
}
# @{N="User";E={((Get-ItemProperty ("Registry::HKEY_USERS\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" + $_ + "\Volatile Environment") -ErrorAction SilentlyContinue).PSObject.Properties | Where-Object {$_.Name -eq "USERNAME"} | Select-Object Value).Value}}
# Change Key
IF ($Action -eq "Change") {
ForEach ($FullKey in $Keys) {
If (!(Get-Item -Path $FullKey.Path -ErrorAction SilentlyContinue)) {
New-Item -Path $FullKey.Path -Force
}
Set-ItemProperty -Path $FullKey.Path -Name $Name -Value $Value -Type $Type
}
}
# Check Key
$RegValues = @()
ForEach ($FullKey in $Keys) {
$RegValues += (Get-ItemProperty -Path $FullKey.Path -ErrorAction SilentlyContinue).PSObject.Properties | Where-Object {$_.Name -eq $Name} | Select-Object Name, TypeNameOfValue, Value, @{N="User";E={$FullKey.User}}
}
# Output Results
ForEach ($RegValue in $RegValues) {
If ($RegValue.User) {$UserScript = ($RegValue.User + " - ")} Else {$UserScript = ""}
$ScriptOut = $UserScript.ToString() + $RegValue.Name.ToString() + " = " + $RegValue.Value.ToString() + " (Reg Type = " + $RegValue.TypeNameOfValue.ToString() + ")"
Write-Output $ScriptOut.ToString()
}
} Catch {
Write-Output "Failed: $_"
Exit 1
}