dsccommunity / xPSDesiredStateConfiguration

DSC resources for configuring common operating systems features, files and settings.
https://dsccommunity.org
MIT License
209 stars 132 forks source link

xRegistry: Unable to create binary registry value with data '0x00' #276

Closed Amedama96 closed 7 years ago

Amedama96 commented 7 years ago

Description

I want to create binary registry value with data '0x00', but xRegistry resource set none value.

Detail

I want to create binary reg value with data zero zero

For that, write and exec psdsc configuration like...

xRegistry Zero_RegBinary
{
    Ensure = "Present"
    Key = "HKEY_LOCAL_MACHINE\SYSTEM\Tests"
    ValueName = "TestValue"
    ValueData = "0x00"    # same result if you set ValueData="0", 
    ValueType = "Binary"
}

Then, sadly, xRegistry resource create a reg value that has 'zero-length binary value' none

I confirmed the issue also have the In-box Regisrtry resource in Windows 10 1607.

How to fix

I've discovered the issue caused by this code.

$val = $Data[0].TrimStart('0x')

Apparently the code is intended to remove the first '0x' of $Data[0]. but if $Data[0] = '0' or '0x00', empty value is set in $val. Perhaps this is undesired behavior.

I would like to propose to modify the code like...

if($Data[0].StartsWith('0x')) {
   $val = $Data[0].Substring(2)
}
else {
   $val = $Data[0]
}

It's a little redundant, but I think it is easy to understand and behave properly.

Amedama96 commented 7 years ago

This issue fixed and merged #299 by @kwirkykat