Skip to content

Instantly share code, notes, and snippets.

@davidwallis3101
Last active March 1, 2024 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwallis3101/52b8bf34a2363c1c80832b745c43da50 to your computer and use it in GitHub Desktop.
Save davidwallis3101/52b8bf34a2363c1c80832b745c43da50 to your computer and use it in GitHub Desktop.
Registry key / value enumeration
[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