Can Powershell Get-ChildProperty get a list of real registry keys like REG QUERY can without extra noise?

Can Powershell Get-ChildProperty get a list of real registry keys like REG QUERY can without extra noise?

This is a trick:

Get-ItemProperty HKCU:SoftwareMicrosoftCharMap  | out-string -stream | ? { $_ -NOTMATCH ^ps.+ }

The problem is when a property start with PS . Working on this code you can elaborate to exclude these:

PSPath
PSParentPath
PSChildName
PSDrive
PSProvider

… One by one inside the where clause. Or just try using

get-item hkcuSoftwareMicrosoftCharMap

There a script that do what you need.

update reproduced script here:

Function Get-RegistryKeyPropertiesAndValues
{
  <#
    Get-RegistryKeyPropertiesAndValues -path HKCU:Volatile Environment
    Http://www.ScriptingGuys.com/blog
  #>

 Param(

  [Parameter(Mandatory=$true)]
  [string]$path)

 Push-Location
 Set-Location -Path $path
 Get-Item . |
 Select-Object -ExpandProperty property |
 ForEach-Object {
 New-Object psobject -Property @{property=$_;
    Value = (Get-ItemProperty -Path . -Name $_).$_}}
 Pop-Location
} #end function Get-RegistryKeyPropertiesAndValues

Following code will enumerate all values for a certain Registry key, will sort them and will return value name : value pairs separated by colon (:):

$path = HKLM:SOFTWAREWow6432NodeMicrosoft.NETFramework;

Get-Item -Path $path | Select-Object -ExpandProperty Property | Sort | % {
    $command = [String]::Format((Get-ItemProperty -Path {0} -Name {1}).{1}, $path, $_);
    $value = Invoke-Expression -Command $command;
    $_ +  :  + $value; };

Like this:

DbgJITDebugLaunchSetting : 16

DbgManagedDebugger : C:Windowssystem32vsjitdebugger.exe PID %d APPDOM %d EXTEXT %s EVTHDL %d

InstallRoot : C:WindowsMicrosoft.NETFramework

Can Powershell Get-ChildProperty get a list of real registry keys like REG QUERY can without extra noise?

Heres my substitute script for get-itemproperty I call get-itemproperty2.ps1:

# get-childitem skips top level key, use get-item
param([parameter(ValueFromPipeline)]$key)

process { 
  $valuenames = $key.getvaluenames() 

  if ($valuenames) { 
    $valuenames | foreach {
      $value = $_
      [pscustomobject] @{
        Path = $key -replace HKEY_CURRENT_USER,
          HKCU: -replace HKEY_LOCAL_MACHINE,HKLM:
        Name = $Value
        Value = $Key.GetValue($Value)
        Type = $Key.GetValueKind($Value)
      }
    }
  } else {
    [pscustomobject] @{
      Path = $key -replace HKEY_CURRENT_USER,
        HKCU: -replace HKEY_LOCAL_MACHINE,HKLM:
        Name = 
        Value = 
        Type = 
    }
  }
}

Example:

get-item hkcu:key1 | get-itemproperty2

Path       Name  Value  Type
----       ----  -----  ----
HKCU:key1 name1     1 DWord

Leave a Reply

Your email address will not be published.