DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Calling "PSDesiredStateConfiguration/WindowsOptionalFeature" Fails with Error

Open ChaosBlade10101 opened this issue 1 month ago • 3 comments

Prerequisites

  • [x] Write a descriptive title.
  • [x] Make sure you are able to repro it on the latest version
  • [x] Search the existing issues.

Summary

I have been experimenting with DSC and have encountered an Error with what i belive is the "PSDesiredStateConfiguration/WindowsOptionalFeature" resource when using the attached document

test.config.dsc.yaml

I continuously encountered the following error:

NativeErrorCode : Failed
ErrorData       : MSFT_WmiError
MessageId       : MI RESULT 1
ErrorSource     :
ErrorType       : 0
StatusCode      : 1
Message         : A general error occurred that is not covered by a more specific error code.
Data            : {}
InnerException  :
TargetSite      : Void ProcessNativeCallback(Microsoft.Management.Infrastructure.Native.OperationCallbackProcessingContext, T, Boolean, Microsoft.Management.Infrastructure.Native.MiResult,
                  System.String, Microsoft.Management.Infrastructure.Native.InstanceHandle)
StackTrace      :    at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext,
                  T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)
HelpLink        :
Source          : Microsoft.Management.Infrastructure
HResult         : -2146233088

When investigation dsc logs i have managed to identity this event

Job {DE97456C-C6CA-11F0-811C-010101010000} : 
Message Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.Object[]'. 
HResult -2147467262 
StackTrack    at System.Management.Automation.LanguagePrimitives.ConvertTo[T](Object valueToConvert)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.ResourceProviderAdapter.GetPSObjectArrayValue(CimType cimType, Object propertyValue)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.ResourceProviderAdapter.GetTargetResource(IntPtr resourceConfigurationInstanceHandle, IntPtr nonResourcePropetiesHandle, IntPtr metaConfigHandle, IntPtr regInstanceHandle, IStreamHandler plugInStreamsHandler, IntPtr& outputInstanceHandle, IntPtr& errorInstanceHandle)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscPluginManagedEntryWrapper.Get(IntPtr provContext, IntPtr instance, IntPtr nonResourcePropeties, IntPtr metaConfig, IntPtr regInstance, IntPtr outputInstance, IntPtr extendedError)

followed by this one which i believe to be the cause of the issue

Job {DE97456C-C6CA-11F0-811C-010101010000} : 
MIResult: 1
Error Message: NULL
Message ID: NULL
Error Category: 0
Error Code: 0
Error Type: NULL

Steps to reproduce

  1. use the following config file
$schema: https://aka.ms/dsc/schemas/v3.0.0/config/document.json
resources:
  - name: "Enable HyperV"
    type: Microsoft.Windows/WindowsPowerShell
    properties:
      resources:
        - name: "Enable HyperV"
          type: "PSDesiredStateConfiguration/WindowsOptionalFeature"
          properties:
              Name: "Microsoft-Hyper-V-All"
  1. Execute the following command line with the saved config file

    dsc.exe config get --file "F:\Homelab_DSC\test.config.dsc.yaml" -o yaml
    

Expected behavior

i expect to get an actual result not an Error

Actual behavior

returns Error Message

Error details

NativeErrorCode : Failed
ErrorData       : MSFT_WmiError
MessageId       : MI RESULT 1
ErrorSource     :
ErrorType       : 0
StatusCode      : 1
Message         : A general error occurred that is not covered by a more specific error code.
Data            : {}
InnerException  :
TargetSite      : Void ProcessNativeCallback(Microsoft.Management.Infrastructure.Native.OperationCallbackProcessingContext, T, Boolean, Microsoft.Management.Infrastructure.Native.MiResult,
                  System.String, Microsoft.Management.Infrastructure.Native.InstanceHandle)
StackTrace      :    at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext,
                  T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)
HelpLink        :
Source          : Microsoft.Management.Infrastructure
HResult         : -2146233088

Environment data

PSVersion                      5.1.26100.7019
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.26100.7019
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1,

PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.1.1

Visuals

No response

ChaosBlade10101 avatar Nov 21 '25 11:11 ChaosBlade10101

WindowsOptionalFeature requires to run as admin, are you running it in an admin prompt? You can also update your config doc to check that the securityContext is elevated.

$schema: https://aka.ms/dsc/schemas/v3.0.0/config/document.json
metadata:
  Microsoft.DSC:
    securityContext: elevated
resources:
  - name: "Enable HyperV"
    type: Microsoft.Windows/WindowsPowerShell
    properties:
      resources:
        - name: "Enable HyperV"
          type: "PSDesiredStateConfiguration/WindowsOptionalFeature"
          properties:
              Name: "Microsoft-Hyper-V-All"

ThomasNieto avatar Nov 21 '25 17:11 ThomasNieto

I have confirmed I am running PowerShell as admin and the security context is elevated; however, I receive the same error, even tried running as system with psexec - i can access the wmi class normally without issue

ChaosBlade10101 avatar Nov 22 '25 02:11 ChaosBlade10101

@ChaosBlade10101 - looking more closely at the error message indicates that there might be a conflicting module. Have you tried running the above example using Invoke-DscResource, rather than using dsc.exe first?

Gijsreyn avatar Nov 23 '25 07:11 Gijsreyn

after doing further testing i was able to narrow the issue down to the actual module - the line that causes the issue seems to be "$result = Dism\Get-WindowsOptionalFeature -FeatureName $Name -Online -Verbose:$false" however this only causes issues when invoked using dsc there is no issues during a manual executation of the module command and the input has been tested and is getting the right result

ChaosBlade10101 avatar Dec 06 '25 03:12 ChaosBlade10101