weird error going through hklm:\software\classes

Welcome Forums General PowerShell Q&A weird error going through hklm:\software\classes

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #110782
    js

    Participant
    Points: 318
    Helping Hand
    Rank: Contributor

    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}
      }
    }
  • #110794
    js

    Participant
    Points: 318
    Helping Hand
    Rank: Contributor

    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
    
  • #111323

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

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

    • #111326

      Participant
      Points: 861
      Helping Hand
      Rank: Major Contributor

      Great point DJ 👍

The topic ‘weird error going through hklm:\software\classes’ is closed to new replies.