Dsc_resource will not work with composite resources


FYI. Invoke-DSCResource cmdlet which dsc_resource relying on will not work with composite resource and this seems to be confirmed bug by Microsoft. Upvote it for fixing please https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/13744065-invoke-dscresource-on-windowsfeatureset-fails


@artisticcheese ,

Composite resources aren’t “real” resources in the eyes of the Local Configuration Manager. Composite resources are used by the “configuration” keyword from the PSDesiredStateConfiguration module and evaluated in that context. When using DSC to create the configuration document (the MOF file) from the configuration command, the composite resource is evaluated and any individual resources from that composite resource are written into the MOF document. As far as the LCM is concerned, there is no such thing as a composite resource. Unless that changes, dsc_resource / Invoke-DscResource cannot directly use them.


Well, good to know but this is not documented neither on Chef or Microsoft side. Probably shall be a note in both places about limitation of using dsc_resource


I filed an issue to get our docs updated with that clarification - https://github.com/chef/chef-web-docs/issues/59


Can I use composite resources with dsc_script resource within Chef? It fails

dsc_script ‘InstallAllPrerequisits’ do
code <<-EOH
Import-DSCResource -ModuleName PSdesiredStateConfiguration
WindowsFeatureSet AllFeatures
Name = “FileAndStorage-Services”,“Storage-Services”,“Web-Server”,"Web-WebServer"
Ensure = Present


Powershell Cmdlet failed: PSDesiredStateConfiguration\node : The term ‘Present’ is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\Windows\Temp\chef-dsc-script20160517-2688-1es63if\chef_dsc_config.ps1:5

  • node ‘localhost’
  • + CategoryInfo          : ObjectNotFound: (Present:String) [PSDesiredState 

Configuration\node], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException,PSDesiredStateConfigura

trap [Exception] {write-error -exception (_.Exception.Message);exit 1};. 'C:/W indows/Temp/chef-dsc-script20160517-2688-1es63if/chef_dsc_config.ps1';chef_dsc -outputpath 'C:/Windows/Temp/chef-dsc-script20160517-2688-1es63if/chef_dsc' 4> 'C:/Windows/Temp/verbose20160517-2688-16xttjo';if ( ! ? ) { exit 1 } :
Errors occurred while processing configuration ‘chef_dsc’.
+ CategoryInfo : NotSpecified: (:slight_smile: [Write-Error], Exception
+ FullyQualifiedErrorId : System.Exception


Present needs to be quoted "Present".


Another thing @artisticcheese - don’t use import-dscresource inside the code block. There is an imports property where you can specify the modules to import. The way that we build the configuration, your import-dscresource ends up in the node block where it is invalid.