Set-ItemProperty sets Registry Value as String on some systems instead of DWord, why? Set-ItemProperty sets Registry Value as String on some systems instead of DWord, why? powershell powershell

Set-ItemProperty sets Registry Value as String on some systems instead of DWord, why?


I don't have an answer to why it happens but to avoid such instances, be explicit. Use the Type (dynamic) Parameter and specify a RegistryValueKind value (you can also use it with New-ItemProperty) :

Set-ItemProperty -Path HKCR:\Software\MyCompany -Name Level -Value 5 -Type DWord


Try this.

[Microsoft.Win32.Registry]::SetValue("HKEY_CLASSES_ROOT\Software\MyCompany","Level",5,[Microsoft.Win32.RegistryValueKind]::DWord)