PowerShell / DSC

This repo is for the DSC v3 project
MIT License
195 stars 24 forks source link

Script based resources do not enforce schema validation #236

Open mgreenegit opened 10 months ago

mgreenegit commented 10 months ago

Prerequisites

Steps to reproduce

'{"Name": "bits","State": "Running"}' | dsc resource get -r PsDscResources/MSFT_ServiceResource

Expected behavior

actualState:
  DesktopInteract: false
  Name: bits
  BuiltInAccount: LocalSystem
  State: Stopped
  Ensure: Present
  Description: Transfers files in the background using idle network bandwidth. If the service is disabled, then any applications that depend on BITS, such as Windows Update or MSN Explorer, will be unable to automatically download programs and other information.
  StartupType: Manual
  Dependencies:
  - RpcSs
  Path: C:\WINDOWS\System32\svchost.exe -k netsvcs -p
  DisplayName: Background Intelligent Transfer Service

Actual behavior

Error: Command: Resource 'DSC/PowerShellGroup' [Exit code 1] Get-TargetResource: A parameter cannot be found that matches parameter name 'State'.

Error details

This happens because script based resources do not enforce parameter validation, and in many cases "Get" does not implement all parameters.
Example:
https://github.com/PowerShell/PSDscResources/blob/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_ServiceResource/MSFT_ServiceResource.psm1#L37

We could solve this issue in PSDesiredStateConfiguration, but then DSCv3 would require that version or later. When we have created dependencies like that in the past, it made adoption more difficult.

Environment data

7.3.8

Version

0.2.0

Visuals

No response