Jorge Rebelo
Jorge Rebelo

Reputation: 33

Save the hexadecimal value from a Reg_Binary key on a variable

I Need to extract the value of a REG_BINARY from the registry without make an array. Need to have the value on one line only

#create Object
$Contentor ="" | Select "HostGUID"

#Read the registry key with REG_BINARY
  $SyLinkScan = Get-ItemProperty -Path 'HKLM:\\SOFTWARE\WOW6432Node\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink'

$Save the RegKey on the object
$Contentor.HostGUID =  $SyLinkScan.HostGUID

The current value that I'm getting the converted value: PS C:\Intel\SEPReg> $Contentor.HostGUID 43 73 212 115 145 230 15 121 58 87 183 134 186 181 116 73

Need the following Result: PS C:\Intel\SEPReg> $Contentor.HostGUID 2B49D47391E60F793A57B786BAB57449

Upvotes: 0

Views: 433

Answers (2)

Theo
Theo

Reputation: 61253

Or use the BitConverter class:

$SyLinkScan = Get-ItemProperty -Path 'HKLM:\\SOFTWARE\WOW6432Node\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink'
$Contentor  = [PsCustomObject]@{ 'HostGUID' = [System.BitConverter]::ToString($SyLinkScan.HostGUID) -replace '-'}

$Contentor
HostGUID                        
--------                        
2B49D47391E60F793A57B786BAB57449

Upvotes: 0

Scepticalist
Scepticalist

Reputation: 3923

Turn it back into hex like this?

#create Object
$Contentor ="" | Select "HostGUID"

#Read the registry key with REG_BINARY
  $SyLinkScan = Get-ItemProperty -Path 'HKLM:\\SOFTWARE\WOW6432Node\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink'

$Save the RegKey on the object
$SyLinkScan.HostGUID | ForEach { 
    $Contentor.HostGUID += "{0:x}" -f $_
}

Upvotes: 1

Related Questions