Can Powershell Get-ChildProperty get a list of real registry keys, such as REG QUERY, without additional noise?

In PowerShell 2.0 on Win2008R2, if I want to get the same result from a registry key that "REG QUERY" will provide me, as a readable format, the values ​​from a specific registry key, for example:

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 can I do this using PowerShell? PowerShell's behavior puzzles me again.

Get-ItemProperty example:

 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 far-fetched example above, I want to see "Advanced", "CodePage" and "Font", but not any PowerShell metadata (names starting with PS). Unfortunately, filtering on the name “PS” will not work for me, because I DO NOT really try to read the settings for the MS Windows character map, I just selected them as a registry key, which is probably for everyone with Windows, so everyone can see how a completely different experience using PowerShell is to look at the registry, compared to the REG.EXE program. There are reasons why someone might want to get only registry values ​​from the registry key without getting any metadata, and anyone who writes tools in PowerShell might want to complete this simple task.

I would like the result to be similar to REG QUERY , but still in its own PowerShell format, and not just flattened to text. I googled and searched everywhere and can't seem to figure it out.

I would like to do this, for example:

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

Update . Using the function below works great.

Example Get-RegistryKeyPropertiesAndValues -path HKCU:\Software\.....

+4
source share
4 answers

This is the trick:

 Get-ItemProperty HKCU:\Software\Microsoft\CharMap | out-string -stream | ? { $_ -NOTMATCH '^ps.+' } 

The problem is that the property starts with PS . By working on this code, you can develop to exclude them:

 PSPath PSParentPath PSChildName PSDrive PSProvider 

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

 get-item hkcu\Software\Microsoft\CharMap 

There the script does what you need.

update the 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 
+5
source

The following code will list all the values ​​for a specific registry key, sort them and return name values: pairs of values ​​separated by a colon (:):

 $path = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.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: \ Windows \ system32 \ vsjitdebugger.exe" PID% d APPDOM% d EXTEXT "% s" EVTHDL% d

InstallRoot: C: \ Windows \ Microsoft.NET \ Framework \

+1
source

Here is my replacement script for get-itemproperty, which 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 
0
source

Oh no...

 powershell gp 'HKCU:Software\Microsoft\CharMap'|more +7 
-1
source

Source: https://habr.com/ru/post/1445603/


All Articles