Composite DSC resources with parameters

Hi all,

I’m having troubles supplying a composite resource with parameters. See http://stackoverflow.com/questions/22250744/powershell-dsc-composite-resources-with-parameters-not-working. Has anyone encountered the same problem?

Thanks!

I have tried running the following, based on your example, and it works perfectly fine on the test computer (WIn8.1).

baseconfig.schema.psm1

Configuration BaseConfig
{    
    PARAM (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Teststring
    )
    
    File testfile
    {
        DestinationPath = "C:\testfile.txt";
        Contents = $teststring;
    }
}

testconfig.ps1:

import-module baseconfig -force

configuration testconfig
{
    import-dscresource -modulename baseconfig
    
    node localhost
    {
        BaseConfig common
        {
            TestString = "some value for the test string"
        }
    }
}

testconfig

Hi Robert,

I did exactly that. But when running it, it complains about the parameters:


cmdlet BaseConfig at command pipeline position 1
Supply values for the following parameters:
Teststring: 
PSDesiredStateConfiguration\node : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At E:\Dev\DSCResources\Modules\testconfig.ps1:7 char:5
+     node localhost
+     ~~~~
    + CategoryInfo          : MetadataError: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ArgumentIsEmpty,PSDesiredStateConfiguration\node
Errors occurred while processing configuration 'testconfig'.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2088 char:5
+     throw $errorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (testconfig:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

BTW, I’m running Windows 2012R2 with all the latest updates. How important is the directory structure? I’m running the modules from a path included in the $psModulePath environment variable, in a subdir Modules\BaseConfig:

E:\Dev\DSCResources\Modules\testconfig.ps1
E:\Dev\DSCResources\Modules\BaseConfig\baseconfig.psd1
E:\Dev\DSCResources\Modules\BaseConfig\baseconfig.schema.psm1

Is this the correct way? Moving the tree to C:\Program Files\WindowsPowerShell\Modules\BaseConfig did not help.

I’ve asked for a little more detailed information on your stackoverflow question, to see if I can successfully recreate the issue locally on my computer. Could you please edit your question there with the above mentioned information and the information I request in my comment there.

Also, it’d be nice if you’d provide a name on stackoverflow instead of being named ‘user1559544’. :slight_smile:

Hi Robert, thanks for your help. I changed my name and added more details :slight_smile:

Wrote a blog post based on your StackOverflow question. The blog post holds a guide on creating a composite DSC configuration. Thought I should post a link to the blog post here, in case someone finds this thread through an internet search.