Skip to content

Instantly share code, notes, and snippets.

@Chirishman
Last active February 26, 2018 18:37
Show Gist options
  • Save Chirishman/c97ef3f18d0811faf68ae4d9628a1936 to your computer and use it in GitHub Desktop.
Save Chirishman/c97ef3f18d0811faf68ae4d9628a1936 to your computer and use it in GitHub Desktop.
Install Registry Tweaks
@{
'HKLM:\SOFTWARE\Classes\AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723'=@{
'NoOpenWith'=@{
Val=''
Type='String'
}
'NoStaticDefaultVerb'=@{
Val=''
Type='String'
}
}
'HKLM:\SOFTWARE\Classes\AppX4hxtad77fbk3jkkeerkrm0ze94wjf3s9'=@{
'NoOpenWith'=@{
Val=''
Type='String'
}
'NoStaticDefaultVerb'=@{
Val=''
Type='String'
}
}
'HKCU:\SOFTWARE\Classes\AppX4hxtad77fbk3jkkeerkrm0ze94wjf3s9'=@{
'NoOpenWith'=@{
Val=''
Type='String'
}
'NoStaticDefaultVerb'=@{
Val=''
Type='String'
}
}
'HKCU:\SOFTWARE\Classes\AppXd4nrz8ff68srnhf9t5a8sbjyar1cr723'=@{
'NoOpenWith'=@{
Val=''
Type='String'
}
'NoStaticDefaultVerb'=@{
Val=''
Type='String'
}
}
}
function Install-RegistryTweaks {
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline=$True)]
[Alias('InputObject')]
[hashtable]$RegistryTweaks
)
$RegistryTweaks.GetEnumerator() | %{
$path = $_.Key -split "\\"
if (-not (Test-Path $_.Key)){
Write-Verbose "Key doesn't exist, beginning to recursively create subkeys"
0..($path.length - 1) | %{
if (-not (Test-Path ($path[0..$_] -join "\"))){
Write-Verbose "Creating subkey $($path[$_]) in $($path[0..($_-1)] -join "\")"
(get-item ($path[0..($_-2)] -join "\")).OpenSubKey($path[$_-1],$true).CreateSubKey($path[$_])
}
}
}
Write-Verbose "Opening Target Key $($_.Key)"
$thisKey = (get-item ($path[0..($path.Length-2)] -join "\")).OpenSubKey($path[$path.Length-1],$true)
$_.Value.GetEnumerator() | % {
if (($thisKey.GetValue($_.Key) -eq $_.Value.Val)) {
Write-Verbose "Value $($_.Key) = $($_.Value.Val) value already set"
} else {
Write-Verbose "Writing Value $(($_.Key, $_.Value.Val, [Microsoft.Win32.RegistryValueKind]::($_.Value.Type)) -join ", ")"
$thisKey.SetValue($_.Key, $_.Value.Val, [Microsoft.Win32.RegistryValueKind]::($_.Value.Type))
}
}
}
}
@Chirishman
Copy link
Author

[Breaking Change] - Changed to expect an input object with string values in the Type property instead of RegistryValueKinds. This allows storage of the objects in PSD1 files. PSD1 files don't support OrderedDictionary objects so I've removed that constraint. Usage now looks like:

@(
    'C:\Fakepath\AntiEdgeHijack.psd1',
    'C:\Fakepath\AntiPoodleRC4.psd1'
) | %{
    Import-PowerShellDataFile -Path $_  | Install-RegistryTweaks -Verbose
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment