Skip to content

Building mof file ignores any -ErrorAction SilentlyContinue in DSC Resources #35

@ThePSAdmin

Description

@ThePSAdmin

When converging in test-kitchen, it fails with the following error:

if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 1DEA0CC5-2ABF-411C-A74A-BBA3FC0AD01A

D      [WinRM] creating command_id: 1DEA0CC5-2ABF-411C-A74A-BBA3FC0AD01A on shell_id 0B323920-4972-4FB8-90E4-949E4EC637C4
D      [WinRM] Waiting for output...
D      [WinRM] Processing output
       Get-ItemProperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\PowerShell\3\DSC' because it does not exist.
       At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:607
       char:32
       + ...      $reg = Get-ItemProperty -path $key -name "PSDscAllowPlainTextPas ...
       +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           + CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...owerShell\3\DSC:String) [Get-ItemProperty], ItemNotFo

After troubleshooting, I found that in this code block https://github.com/test-kitchen/kitchen-dsc/blob/master/lib/kitchen/provisioner/dsc.rb#L124

the mof file is built, but any errors that are ignored in the dsc resources causes kitchen-dsc to exit. In this case, its the following line from the build in PSDesiredStateConfiguration module:

$reg = Get-ItemProperty -path $key -name "PSDscAllowPlainTextPassword" -ea SilentlyContinue

I'm guessing the checking of the $error variable was put there for a reason, so I thought I'd check via this issue before opening a pull request. Otherwise a suggested fix is using -erroraction stop when compiling the mof and adding the exit code to the catch block.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions