Pulling exact Hex string from registry

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of ertuu85 ertuu85 1 year, 8 months ago.

  • Author
    Posts
  • #29549
    Profile photo of ertuu85
    ertuu85
    Participant

    Hello, i have a function that pulls values out of the registry in decimal format, but I'm wanting to pull it so it pulls it exactly as it states it in the registry

    What I mean is say I have a key HKLM:\SOFTWARE\TEST\ key1 with a value ffffffff

    when i run my function it pulls it as a -1 (i'm guess because every thing 7fffffff is a count down back to -1)

    Is there a way to pull the exact hex from the registry? or a method to convert say -1 to it's hex value in the registry?

    function get-registryvalue($regkey, $name)
    {
    (get-itemproperty -path $regkey).$name
    }

    get-registeryvalue hklm:\software\test key1

    >> -1

  • #29552
    Profile photo of Curtis Smith
    Curtis Smith
    Participant


    PS C:\> '{0:x}' -f -1
    ffffffff

    therefore

    '{0:x}' -f (get-itemproperty -path $regkey).$name

    http://ss64.com/ps/syntax-f-operator.html

  • #29553
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    Try to use the format operator -f as shown below:

    '0x{0:x}' -f (get-registeryvalue hklm:\software\test key1)
    
  • #29556
    Profile photo of ertuu85
    ertuu85
    Participant

    Thank you both!

You must be logged in to reply to this topic.