Using Powershell to manage binary registry keys

Managing Binary Registry Keys

Microsoft has a guide here on Working with registry entries.

It’s pretty good for most purposes but I found it needed an example for a common issue: I have a binary key set correctly on one machine, how do I deploy this? This is pretty common trying to manage certain settings with Intune for example. In this case, we have a printer config.

First, let’s get a copy of the current key in hex. It will output a large string.

$settings = Get-ItemPropertyValue  -Path "HKCU:\Printers\DevModePerUser" -Name "PrinterName"
$($settings -join ',')

Now here’s the script we deployed. Just paste the output above into the assignment.


If (-Not (Test-Path 'HKCU:\Printers\DevModePerUser'))
{
    New-Item 'HKCU:\Printers\DevModePerUser' -Force | Out-Null
}

$sHex = @(<insert string>)
$sBin = [byte[]]($sHex)

New-ItemProperty -Path "HKCU:\Printers\DevModePerUser" -Name "PrinterName" -Value $sBin -PropertyType Binary -Force