weird error going through hklm:\software\classes

I’m trying to script going through the registry and handing back key,value,data, but I get a weird error around hklm:\software\classes.

I know it’s running

get-itemproperty -path Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Classes* -name AlwaysShowExt
but why?

PS C:\users\admin> .\get-reg HKLM:\SOFTWARE\Classes\

get-itemproperty -path Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Classes\* -name AlwaysShowExt

get-itemproperty : Property AlwaysShowExt does not exist at path HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.386.
At C:\users\ccfadmin\get-reg.ps1:36 char:15
+       $data = get-itemproperty -path $path -name $name | select -expa ...
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (AlwaysShowExt:String) [Get-ItemProperty], PSArgumentException
    + FullyQualifiedErrorId : System.Management.Automation.PSArgumentException,Microsoft.PowerShell.Commands.GetItemPr
   opertyCommand

Here’s the script:

# get-reg.ps1

Param($key)

Get-ChildItem -Recurse $key | foreach { # won't process top key
  $path = $_.PSPath
  $_.Property | foreach {
    $name = $_

    "get-itemproperty -path $path -name $name"
    $data = get-itemproperty -path $path -name $name | select -expand $name
    [pscustomobject]@{key=$path; value=$name; data=$data}
  }
}

I figured it out. There’s a key named “*” under hklm:\software\classes, lol. I’ll just use -literalpath instead.

# get-reg.ps1

Param($key)

Get-ChildItem -Recurse $key | foreach { # won't process top key
  $path = $_.PSPath
  $_.Property | foreach {
    $name = $_

    $data = get-itemproperty -literalpath $path -name $name | 
      select -expand $name
    [pscustomobject]@{key=$path; value=$name; data=$data}
  }
}

Output:

PS C:\Users\admin> .\get-reg hklm:\software\classes | fl | Out-host -Paging


key   : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\classes\*
value : AlwaysShowExt
data  :

key   : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\classes\*
value : ConflictPrompt
data  : prop:System.ItemTypeText;System.Size;System.DateModified;System.DateCreated

key   : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\classes\*
value : ContentViewModeForBrowse
data  : prop:~System.ItemNameDisplay;System.ItemTypeText;~System.LayoutPattern.PlaceHolder;~System.LayoutPattern.PlaceH
        older;System.DateModified;System.Size

As a note, -LiteralPath was made for the Registry, because it uses so many characters that are “illegal” in a file path.

Great point DJ :+1: