dsccommunity / ComputerManagementDsc

DSC resources for for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings.
https://dsccommunity.org
MIT License
302 stars 83 forks source link

WindowsCapability - Test-TargetResource fails #297

Closed davehl7 closed 4 years ago

davehl7 commented 4 years ago

An attempt to test WindowsCapability resource fails.

Details of the scenario you tried and the problem that is occurring

Trying to handle capability resource 'SNMP.Client~~~~0.0.1.0' via following script: WindowsCapability SNMP { Name = 'SNMP.Client~~~~0.0.1.0' Ensure = 'Present' }

Verbose logs showing the problem

VERBOSE: An LCM method call arrived from computer COMP-XYZ with user sid S-1-5-21-xyz. VERBOSE: [COMP-XYZ]: LCM: [ Start Compare ] VERBOSE: [COMP-XYZ]: LCM: [ Start Resource ] [[WindowsCapability]SNMP::[WindowsFeatures]DefaultOSFeatures] VERBOSE: [COMP-XYZ]: LCM: [ Start Test ] [[WindowsCapability]SNMP::[WindowsFeatures]DefaultOSFeatures] VERBOSE: [COMP-XYZ]: [[WindowsCapability]SNMP::[WindowsFeatures]DefaultOSFeatures] Begin executing Test functionality on Windows Capability 'SNMP.Client~~~~0.0.1.0'. A parameter cannot be found that matches parameter name 'Ensure'.

PowerShell Desired State Configuration does not support execution of commands in an interactive mode. Please ensure that the underlying command is not prompting for user input, such as missing mandatory parameter, confirmation prompt etc.

Suggested solution to the issue

It seems that Test-TargetResource passes unexpected parameters to Get-WindowsCapability. Parameter set should be handled in a similar way as in Set-TargetResource.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

    WindowsCapability SNMP {
        Name = 'SNMP.Client~~~~0.0.1.0'
        Ensure = 'Present'
    }

The operating system the target node is running

Windows 10 1709 Enterprise

Version and build of PowerShell the target node is running

PSVersion 5.1.16299.1146 PSEdition Desktop

Version of the DSC module that was used ('dev' if using current dev branch)

Using ComputerManagementDsc version 7.1.0.0.

PlagueHO commented 4 years ago

Hi @davehl7 - this does seem to be the case. There is a missing default parameter on the Ensure (https://github.com/dsccommunity/ComputerManagementDsc/blob/dev/DSCResources/MSFT_WindowsCapability/MSFT_WindowsCapability.psm1#L170) as well as a missing command:

$null = $PSBoundParameters.Remove('Ensure')

I'm not sure why the unit tests didn't pick this up. So I'll need to fix these. I'll fix this at the same time as migrating to the new CI process.

PlagueHO commented 4 years ago

Still working on this, but should be finished in the next day or two.