Skip to content

Commit

Permalink
New registery example
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed May 16, 2024
1 parent e0d7556 commit 1b2c313
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Pwsh/Other/QueryRegistryKeysWithResults.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$regKeyPaths = @(
"Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender",
'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System',
'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CI\Config'
)
$iterCount = 0
# Loop through each registry path
$query = @( foreach ($regPath in $regKeyPaths) {
$result = [ordered]@{
Iter = ($IterCount++)
HasError = $false
NoProps = $true
NoValues = $true
Path = $RegPath
}
try {
$result.ItemProps = Get-ItemProperty -Path $regPath
$result.Values = $result.ItemProps |
Select-Object -ExcludeProperty PSPath, PSParentPath, PSChildName, PSProvider
} catch {
$result.HasError = $true
} finally {
$result.NoProps = $result.ItemProps.Count -eq 0
$result.NoValues = $result.Values.Count -eq 0
[pscustomobject]$result
}
})

$query|Ft -auto
$Query.count

# then you can drill down into individual queries
$Query[0]

0 comments on commit 1b2c313

Please sign in to comment.