Quick tip: how to add REG_NONE value

  • Context

A colleague of mine sent me a message saying that I need to add a reg_none value.

Although the referenced article talks about REG_SZ (String Value) – How to suppress the AutoDiscover redirect warning in Outlook – I can only see REG_NONE values under HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\AutoDiscover\RedirectServers

  • Problem

I started to innocently do the following but it failed:

$v = 'autodiscover-s.outlook.com'
$p = 'HKCU:\Software\Microsoft\Office\16.0\Outlook\AutoDiscover\RedirectServers'
Set-ItemProperty -Value $null -Type None -Path $p -Name $v -Force -Verbose
Set-ItemProperty -Value '' -Type None -Path $p -Name $v -Force -Verbose

I ended with the following error messages:
Set-ItemProperty : Value cannot be null.
Set-ItemProperty : The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted


I almost gave up and started to look for an acceptable answer on the web.

  • Solution

The best answer I found is on this page: https://stackoverflow.com/questions/47530823/set-reg-none-value-via-powershell
Kudos to Mathias R. Jessen. He has the solution and the relevant answer! Awesome!

It’s true, the value is a null byte array and it’s revealed by using the Get-Member cmdlet:

$v = 'autodiscover-s.outlook.com'
$p = 'HKCU:\Software\Microsoft\Office\16.0\Outlook\AutoDiscover\RedirectServers'
Get-ItemProperty -Path $p -Name $v | gm

The solution is:

$v = 'autodiscover-s.outlook.com'
$p = 'HKCU:\Software\Microsoft\Office\16.0\Outlook\AutoDiscover\RedirectServers'
Set-ItemProperty -Value ([byte[]]@()) -Type None -Path $p -Name $v -Force -Verbose