Last active
March 1, 2024 08:51
-
-
Save davidwallis3101/52b8bf34a2363c1c80832b745c43da50 to your computer and use it in GitHub Desktop.
Registry key / value enumeration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param( | |
$registryPath = "HKLM:\System\CurrentControlSet\Test" | |
) | |
Function Get-RegistryValue { | |
Param( | |
[Parameter(Mandatory)] | |
[string]$Path | |
) | |
(Get-Item -Path $Path).GetValueNames() | Select-Object @{N="Name"; E={$_}}, @{N="Value"; E={(Get-ItemProperty -Path $Path).$_}} | |
} | |
Function Get-RegistrySubkey { | |
Param( | |
[Parameter(Mandatory)] | |
[string]$Path | |
) | |
Get-ChildItem -Path $Path | Where-Object { $_.PSIsContainer } | |
} | |
If (Test-Path $registryPath) { | |
ForEach ($key in (Get-RegistrySubkey -Path $registryPath)) { | |
ForEach ($value in (Get-RegistryValue -Path $key.PSPath)) { | |
Write-Host "Name: $($value.Name) Value: $($value.Value)" | |
} | |
} | |
ForEach ($value in (Get-RegistryValue -Path $registryPath)) { | |
Write-Host "Name: $($value.Name) Value: $($value.Value)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment