Author Posts

September 9, 2015 at 10:02 am

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

September 9, 2015 at 10:18 am


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

therefore

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

#PSTip Converting numbers to HEX


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

September 9, 2015 at 10:21 am

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

'0x{0:x}' -f (get-registeryvalue hklm:\software\test key1)