How to set a binary registry value (REG_BINARY) with PowerShell? How to set a binary registry value (REG_BINARY) with PowerShell? powershell powershell

How to set a binary registry value (REG_BINARY) with PowerShell?


The following line gives you an example how to create one

New-ItemProperty -Path . -Name Test -PropertyType Binary -Value ([byte[]](0x30,0x31,0xFF))

and how to change an existing one:

Set-ItemProperty -Path . -Name Test -Value ([byte[]](0x33,0x32,0xFF))


This post has helped me out with similar problem. Thanks!

Bringing xBr0k3n and Howard's answers together:

#Change these three to match up to the extracted registry data and run as Admin$YourInput = "50,33,01,00,00,00,00,00,00,00,00,00,03,00,00,00,0e,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00"$RegPath   = 'HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\aspnet_state'$AttrName  = "FailureActions"$hexified = $YourInput.Split(',') | % { "0x$_"}New-ItemProperty -Path $RegPath -Name $AttrName -PropertyType Binary -Value ([byte[]]$hexified)


Is it just me who feels this misses the main part of this question?

How would you go about changing the original:

50,33,01,00,00,00,00,00,00,00,00,00,03,00,00,00,0e,00,00,\00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00

Into a format like:

([byte[]](0x33,0x32,0xFF))

EDIT: After trying to get this working it turns out you just prefix all of the pairs with '0x'. Not sure why that was not mentioned in the answer. So just change the above to:

0x50,0x33,0x01,0x00,0x00,0x00,0x00,0x00... etc.

Then wrap that in the following:

([byte[]](0x50,0x33,0x01,0x00,0x00,0x00,0x00,0x00... etc.))