Writing DWORD-Values to Registry

by Sep 3, 2013

In PowerShell 2.0, Set-ItemProperty by default always creates REG_SZ (String) values. PowerShell 3.0 is smarter. When you submit a numeric value, then PowerShell 3.0 automatically creates a DWORD value. If you submit a non-numeric value, a REG_SZ is created.

Try for yourself! This line will create a REG_SZ value in PowerShell 2.0 and a REG_DWORD value in PowerShell 3.0:

This can lead to unexpected results. That's why you should make sure to specify the data type you want. This line creates DWORD values both in PowerShell 2.0 and 3.0:

Twitter This Tip! ReTweet this Tip!