Composite DSC Resource not working


Trying to use composite DSC ressource and have created the following:

PS C:\Windows\system32> dir 'C:\Program Files\WindowsPowerShell\Modules\CommonConfig\DSCResource\xCommonConfig'

    Directory: C:\Program Files\WindowsPowerShell\Modules\CommonConfig\DSCResource\xCommonConfig

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        09-07-2014     13:11       5240 xCommonConfig.psd1
-a---        09-07-2014     11:26        143 xCommonConfig.schema.psm1
PS C:\Program Files\WindowsPowerShell\Modules\CommonConfig\DSCResource\xCommonConfig> gc .\xCommonConfig.schema.psm1
Configuration CommonConfig {

    WindowsFeature TelnetClient {

    Ensure = 'Present'

    Name = 'Telnet-Client'



The .psd1 file got created by running this:

New-ModuleManifest –Path "C:\Program Files\WindowsPowerShell\Modules\CommonConfig\DSCResource\xCommonConfig\xCommonConfig.psd1" –RootModule "xCommonConfig.schema.psm1" 

However, the module does not show up:

PS C:\> Get-DscResource

ImplementedAs   Name                      Module                         Properties
-------------   ----                      ------                         ----------
Binary          File                                                     {DestinationPath, Attributes, Checksum, Con...
PowerShell      Archive                   PSDesiredStateConfiguration    {Destination, Path, Checksum, DependsOn...}
PowerShell      Environment               PSDesiredStateConfiguration    {Name, DependsOn, Ensure, Path...}
PowerShell      Group                     PSDesiredStateConfiguration    {GroupName, Credential, DependsOn, Descript...
Binary          Log                       PSDesiredStateConfiguration    {Message, DependsOn}
PowerShell      Package                   PSDesiredStateConfiguration    {Name, Path, ProductId, Arguments...}
PowerShell      Registry                  PSDesiredStateConfiguration    {Key, ValueName, DependsOn, Ensure...}
PowerShell      Script                    PSDesiredStateConfiguration    {GetScript, SetScript, TestScript, Credenti...
PowerShell      Service                   PSDesiredStateConfiguration    {Name, BuiltInAccount, Credential, DependsO...
PowerShell      User                      PSDesiredStateConfiguration    {UserName, DependsOn, Description, Disabled...
PowerShell      WindowsFeature            PSDesiredStateConfiguration    {Name, Credential, DependsOn, Ensure...}
PowerShell      WindowsProcess            PSDesiredStateConfiguration    {Arguments, Path, Credential, DependsOn...}
PowerShell      xArchive                  xPSDesiredStateConfiguration   {Destination, Path, CompressionLevel, Depen...
PowerShell      xDSCWebService            xPSDesiredStateConfiguration   {CertificateThumbPrint, EndpointName, Confi...
Composite       xFileUpload               xPSDesiredStateConfiguration   {destinationPath, sourcePath, credential, c...
PowerShell      xPackage                  xPSDesiredStateConfiguration   {Name, Path, ProductId, Arguments...}
PowerShell      xPSEndpoint               xPSDesiredStateConfiguration   {Name, AccessMode, DependsOn, Ensure...}
PowerShell      xRemoteFile               xPSDesiredStateConfiguration   {DestinationPath, Uri, Credential, DependsO...
PowerShell      xService                  xPSDesiredStateConfiguration   {Name, BuiltInAccount, Credential, Dependen...
PowerShell      xWindowsProcess           xPSDesiredStateConfiguration   {Arguments, Path, Credential, DependsOn...}

I have tried numerous time, different folder structure, trying in “C:\Program Files\WindowsPowerShell\DscService\Modules” folder also.

And ofcourse, I also get an error when trying to Import-DSCResource CommonConfig in a .ps1 config file.

Any thoughts?

Best regards


The folder name inside your module folder needs to be “DSCResources”, not “DSCResource”. Try changing that, and if it still doesn’t work, I’ll take a closer look at the code itself.

Hi Dave, thank you very much for your fast reply.

Nicely spotted with the missing “S”. Though, It did not help :frowning:

I also tried moving the .psd1 one step out from the DSCResources folder.

From the DSC Books:

Now you need to create a module manifest for it, in the same folder. The manifest filename must be CommonConfig.psd1:
New-ModuleManifest –Path "\Program Files\WindowsPowerShell\Modules\CommonConfig\CommonConfig.psd1" 
                   –RootModule "CommonConfig.schema.psm1"
  • no DSCResources folder is mentioned?

Best regards

I ran into this exact same issue with my Custom Resource, and the issue ended up being my folder structure was incorrect. I will just break down what I have now that works and you can check and see if it matches what you have.

Path:  C:\Program Files\WindowsPowerShell\Modules\MyModule\DSCResources\MyResource
The .psd1 file is stored under C:\Program Files\WindowsPowerShell\Modules\MyModule
The .psm1 file and the schema.mof file are stored under C:\Program Files\WindowsPowerShell\Modules\MyModule\DSCResources\MyResource
Does that match what you have?

Ah, right. The DSCResources folder is just for normal resources, not composite. For a composite resource, you put both the “schema.psm1” and psd1 files into the root folder of a module, and there doesn’t need to be a DSCResources folder at all.

I’ll play around with this later and see if I can get it working. There may be a couple of errors in the DSC book that need to be ironed out. (One thing that jumps out at me right away is the use of positional parameters when calling Import-DscResource; this will give you an error. You need to type out Import-DscResource -ModuleName someModuleName ).

Edit: On a side note, my composite resource would only show up in the output of Get-DscResource if I first imported the CommonConfig module. It wasn’t automatically detected the way other resources are.

Thank you all for your reply. Unforturnally, changing the folder structure did not help, Jacob.

@Dave> You are right about first importing the module in the PS prompt, then I can see it as an resource:

ImplementedAs   Name                      Module                         Properties
-------------   ----                      ------                         ----------
Composite       CommonConfig              xCommonConfig                  {}

When ‘compiling’ this configuration to a .mof file:

Configuration ServerConfig
    Import-DscResource -ModuleName xCommonConfig
    WindowsFeature IIS
        Ensure = 'Present'
        Name = 'Web-Server'

No errors occours, but the .mof file does not contain anything from the CommonConfig resource.

When I actually use the CommonConfig I get an error, first the configfile:

Configuration ServerConfig
    Import-DscResource -ModuleName xCommonConfig
    WindowsFeature IIS
        Ensure = 'Present'
        Name = 'Web-Server'

    CommonConfig Backup
        Status = "Present"

The error:

PSDesiredStateConfiguration\Configuration : The term 'CommonConfig' 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:\Program Files\WindowsPowerShell\DscService\ConfigFiles\TEST-C01.ps1:3 char:1
+ Configuration ServerConfig
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (CommonConfig:String) [Configuration], ParentContainsErrorRecordExceptio
    + FullyQualifiedErrorId : CommandNotFoundException,Configuration

Errors occurred while processing configuration 'ServerConfig'.
At C:\windows\system32\windowspowershell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2088
+     throw $errorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (ServerConfig:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

My CommonConfig psm1 file:

Configuration CommonConfig {

    WindowsFeature Backup { 

    Ensure = $Status
    Name = 'Windows-Server-Backup' 



Best regards,

OK, ignore what I said earlier about being able to place the composite resources out in the root of a module folder. The only way I’ve been able to get this working reliably in testing is to place the composite resource into a subfolder of DSCResources, just like a normal resource. I wind up with the following folder structure, using your module and resource names:

Directory: C:\Program Files\WindowsPowerShell\Modules\xCommonConfig

Mode LastWriteTime Length Name

d---- 7/9/2014 9:50 AM DSCResources
-a— 7/9/2014 9:50 AM 5248 xCommonConfig.psd1

Directory: C:\Program Files\WindowsPowerShell\Modules\xCommonConfig\DSCResources

Mode LastWriteTime Length Name

d---- 7/9/2014 10:16 AM CommonConfig

Directory: C:\Program Files\WindowsPowerShell\Modules\xCommonConfig\DSCResources\CommonConfig

Mode LastWriteTime Length Name

-a— 7/9/2014 9:50 AM 5236 CommonConfig.psd1
-a— 7/9/2014 10:09 AM 164 CommonConfig.schema.psm1

The good news is, Steven Murawski has already gone through this process, and some of the DSC-related scripts he’s written are already set up to create the proper folders and files. Check out DSC/New-DscCompositeResource.ps1 at master · PowerShellOrg/DSC · GitHub . You can run the command as follows:

New-cDscCompositeResource -ModuleName xCommonConfig -ResourceName CommonConfig

This will take care of creating all the folders, PSD1 files, and a schema.psm1 file with an empty configuration. Then you just open up that file and paste in your current code for the CommonConfig configuration.

I’ve just uploaded some corrections to the DSC book’s section on Composite Resources. I copied and pasted all of the steps from the book, and ran them on a clean system to make sure they all worked properly.

Thank you so much Dave! Everything is working now :slight_smile:

Used Steves script to create the module resource and there was no problem this time. The folder structure was wrong for me. Also thank you Jacob, you were right :slight_smile:

Best regards
Stig Sörnsen

Awesome, glad to hear it is working!