Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-5216

dsc : error converting to integer

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • None
    • None
    • dsc
    • Windows
    • Customer Feedback
    • Needs Assessment

    Description

      Basic Info
      Module Version: 1.3.0
      Puppet Version: 4.9
      OS Name/Version: Windows Server 2012 R2

      The Problem

      Using cAdministrativeTemplateSetting DSC Resource from PolicyFileEditor Module (https://github.com/dlwyatt/PolicyFileEditor) with puppet, there's a problem when one specifyies a value for the Type property (allowed values are: "Unknown","String","ExpandString","Binary","DWord","MultiString","QWord","None") the following error is throwned:

      Error: Failed to apply catalog: Parameter dsc_type failed on Dsc_cadministrativetemplatesetting[test-dsc_cAdministrativeTemplateSetting dword]: Invalid value DWord. Should be a signed Integer at /mnt/puppetnfsdir/environments/rchavesg_dsc/hostgroups/hg_windows_dev/manifests/dsc_tests.pp:42

      The Type property is an Integer. I can be found in the cAdministrativeTemplateSetting resource MOF file definition (https://github.com/dlwyatt/PolicyFileEditor/blob/master/DscResources/PshOrg_AdminTemplateSetting/PshOrg_AdminTemplateSetting.schema.mof):
      {{[write,ValueMap

      {"0","1","2","3","4","7","11","-1"}

      ,Values

      {"Unknown","String","ExpandString","Binary","DWord","MultiString","QWord","None"}

      ] sint32 Type;}}

      If instead of specifying a string as a value for the *dsc_type *property an integer is specified, the following error is thrown:

      Error: Failed to apply catalog: Parameter dsc_type failed on Dsc_cadministrativetemplatesetting[test-dsc_cAdministrativeTemplateSetting dword]: Invalid value '1'. Valid values are Unknown, String, ExpandString, Binary, DWord, MultiString, QWord, None at /mnt/puppetnfsdir/environments/rchavesg_dsc/hostgroups/hg_windows_dev/manifests/dsc_tests.pp:42

      Steps To reproduce the problem.

      First, create a DSC script that works and compare it with the Puppet manifest.

      1. Install the PolicyFileEditor in PowerShell of the target machine:

      PS C:\Users\user>Find-DSCResource -ModuleName PolicyFileEditor
      PS C:\Users\user> Install-Module PolicyFileEditor
      

      2. Run a simple DSC Script on the target Windows machine to prove that the resource works fine:

      Configuration LocalGPO
      {
          param
          (
              [string[]] $NodeName = 'localhost'
          )
       
          Import-DSCResource -ModuleName PolicyFileEditor
       
          Node $NodeName
          {
              cAdministrativeTemplateSetting "RDP Users Home Directory Path"
              {
              #    SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDirUNC 
              #    SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDir
              #    SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDirDrive
                  KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDir"
                  PolicyType = "Machine"
                  Data = "\\servershare\test"
                  Ensure = "Present"
                  Type = "String"
              }
       
              cAdministrativeTemplateSetting "RDP Users Home Directory Letter"
              {
                  KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDirDrive"
                  PolicyType = "Machine"
                  Data = "X:"
                  Ensure = "Present"
                  Type = "String"
              }
       
              cAdministrativeTemplateSetting "RDP Users Home Directory UNC boolean"
              {
                  KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDirUNC"
                  PolicyType = "Machine"
                  Data = "1"
                  Ensure = "Present"
                  Type = "Dword"
              }
       
          }
      }
       
      LocalGPO
      Start-DscConfiguration -Path .\LocalGPO -Wait -Force -Verbose
      

      3. On the target machine, run the command gpupdate to update the Group Policy. Then Check the registry keys in HKLM:SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services . There should be a DWORD key with the name WFHomeDirUNC and value 1 .

      Using a Puppet manifest

      class hg_windows_dev::dsc_tests {
        # test dsc_cadministrativetemplatesetting. This uses a String by default.
        dsc_cadministrativetemplatesetting { 'test-dsc_cAdministrativeTemplateSetting':
          dsc_keyvaluename => 'SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\LicenseServers',
          dsc_policytype   => 'Machine',
          dsc_data         => ['server.test.localgpo.puppet-dsc.com'],
          dsc_ensure       => 'Present',
          # dsc_type         => String
          # dsc_type         => '[Microsoft.Win32.RegistryValueKind]::String'
          # dsc_type         => 1
        }
       
        dsc_cadministrativetemplatesetting { 'test-dsc_cAdministrativeTemplateSetting drive letter':
          dsc_keyvaluename => 'SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirDrive',
          dsc_policytype   => 'Machine',
          dsc_data         => 'X:',
          dsc_ensure       => 'Present',
        }
       
        dsc_cadministrativetemplatesetting { 'test-dsc_cAdministrativeTemplateSetting dword':
          dsc_keyvaluename => 'SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirUNC',
          dsc_policytype   => 'Machine',
          dsc_data         => '1',
          dsc_ensure       => 'Present',
          dsc_type         => 'DWord'
          # dsc_type         => '[Microsoft.Win32.RegistryValueKind]::Dword'
          # dsc_type         => 4
        }
       
      }
      
      

      Note: The lines of the errors documented above do not correspond exactly to the lines in this example puppet manifest (in this example there's no line 42. But it corresponds to the last uncommented line of the last resource dsc_type => 'DWord' ). The commented lines are there to show the other values i tested without any success.

      Desired Behavior:
      Same behavior as a DSC script. I created one to test and compare it.

      Actual Behavior:
      When using Puppet with DSC, errors are thrown when passing any kind of value to dsc_type property (as it shown in the examples).

      The same issue was already submitted by me in the PowerShell github page:
      https://github.com/PowerShell/PowerShell/issues/4046

      Attachments

        Activity

          People

            ricardogaspar2 Ricardo Gaspar
            ricardogaspar2 Ricardo Gaspar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Zendesk Support