OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

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

  • Thread starter Thread starter Warren P
  • Start date Start date
W

Warren P

Guest
In PowerShell 2.0 on Win2008R2, if I want to get the same output from a registry key that "REG QUERY" would give me, in as readable a format, with the values from a particular registry key, like this:

Code:
reg query hkcu\Software\Microsoft\CharMap

HKEY_CURRENT_USER\Software\Microsoft\CharMap
    Advanced    REG_DWORD    0x0
    CodePage    REG_SZ       Unicode
    Font        REG_SZ       Arial

How would I do that with PowerShell? The behaviour of PowerShell mystifies me, once again.

Get-ItemProperty example:

Code:
Get-ItemProperty HKCU:\Software\Microsoft\CharMap


PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\CharMap
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft
PSChildName  : CharMap
PSDrive      : HKCU
PSProvider   : Microsoft.PowerShell.Core\Registry
Advanced     : 0
CodePage     : Unicode
Font         : Arial

In my contrived example above, I want to see "Advanced", "CodePage" and "Font", but not any of the PowerShell metadata (names starting in PS). Sadly filtering on the name "PS" would not work for me, because I am not REALLY trying to read the MS Windows Character Map settings, I simply chose them as a registry key that probably everyone with Windows has, so everyone can see how utterly different the experience of using PowerShell is to look at the registry, compared to say the REG.EXE program. There are reasons why anybody might want to get just the registry values from a registry key without getting any of the metadata, and anybody writing tools in PowerShell may want to do this simple task.

I would like output similar to REG QUERY but still in native PowerShell format, not just flattened to text. I've googled and searched all over and can't seem to figure this out.

I'd like to be able to for example do this:

Code:
  $all = GetRealRegistryKeysFrom(  HKCU:\Software\Microsoft\CharMap )
  for ($item in $all) { ... }

Update Using the function below, works great....

Example Get-RegistryKeyPropertiesAndValues -path HKCU:\Software\.....
<p>In PowerShell 2.0 on Win2008R2, if I want to get the same output from a registry key that "REG QUERY" would give me, in as readable a format, with the values from a particular registry key, like this:</p>

<pre><code>reg query hkcu\Software\Microsoft\CharMap

HKEY_CURRENT_USER\Software\Microsoft\CharMap
Advanced REG_DWORD 0x0
CodePage REG_SZ Unicode
Font REG_SZ Arial
</code></pre>

<p>How would I do that with PowerShell? The behaviour of PowerShell mystifies me, once again. </p>

<p>Get-ItemProperty example:</p>

<pre><code>Get-ItemProperty HKCU:\Software\Microsoft\CharMap


PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\CharMap
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft
PSChildName : CharMap
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
Advanced : 0
CodePage : Unicode
Font : Arial
</code></pre>

<p>In my contrived example above, I want to see "Advanced", "CodePage" and "Font", but not any of the PowerShell metadata (names starting in PS). Sadly filtering on the name "PS" would not work for me, because I am not REALLY trying to read the MS Windows Character Map settings, I simply chose them as a registry key that probably everyone with Windows has, so everyone can see how utterly different the experience of using PowerShell is to look at the registry, compared to say the <code>REG.EXE</code> program. There are reasons why anybody might want to get just the registry values from a registry key without getting any of the metadata, and anybody writing tools in PowerShell may want to do this simple task.</p>

<p>I would like output similar to <code>REG QUERY</code> but still in native PowerShell format, not just flattened to text. I've googled and searched all over and can't seem to figure this out. </p>

<p>I'd like to be able to for example do this:</p>

<pre><code> $all = GetRealRegistryKeysFrom( HKCU:\Software\Microsoft\CharMap )
for ($item in $all) { ... }
</code></pre>

<p><strong>Update</strong> Using the function below, works great....</p>

<p>Example <code>Get-RegistryKeyPropertiesAndValues -path HKCU:\Software\.....</code></p>
Continue reading...
 

Latest posts

Online statistics

Members online
1
Guests online
2
Total visitors
3
Top