Question

I can get a composite resource working at a very basic level (thanks to this SO question, this SO question, this MSDN blog and the DSC e-book). The issue I run into is whenever I use a resource that I have to use the Import-DscResource cmdlet, the composite resource stops working.

I have read all the information I can find on composite resource, and I cannot figure out why this happens. Here is an example of the resource I am trying to get to work, module directory structure first:

C:\Program Files\WindowsPowerShell\Modules\TestComposite
    TestComposite.psd1
    DSCResources
        TestResource
            TestResource.schema.psm1
            TestResource.psd1

Contents of TestComposite.psd1

@{
ModuleVersion = '1.0'
GUID = '996a9793-dae7-4c25-8fb5-d3fad094d358'
Author = 'Joseph Alcorn'
CompanyName = 'unknown'
Copyright = '(c) 2014 Joseph Alcorn. All rights reserved.'
Description = 'Composite DSC Resource Test'
FunctionsToExport = '*'
CmdletsToExport = '*'
VariablesToExport = '*'
AliasesToExport = '*'
}

Contents of TestResource.psd1

@{
RootModule = 'TestResource.schema.psm1'
ModuleVersion = '1.0'
GUID = '38ca17b0-7d69-4ad5-bb75-fe4de22290d
Author = 'Joseph Alcorn'
CompanyName = 'unknown'
Copyright = '(c) 2014 Joseph Alcorn. All rights reserved.'
Description = 'Composite DSC Resource Test'
FunctionsToExport = '*'
CmdletsToExport = '*'
VariablesToExport = '*'
AliasesToExport = '*'
}

If I have the contents of TestResource.schema.psm1 be this, the composite resource is recognized and everything works.

Configuration TestResource
{
    param
    (
        [Parameter(Mandatory=$true)]
        [string]
        $IPAddress
    )

    File TestFile1
    {
        DestinationPath = "C:\TestFile.txt";
        Contents = $IPAddress
    }
}

As soon as I change the configuration to this, it is no longer recognized by Get-DscResource and any configuration trying to use it will error out.

Configuration TestResource
{
    param
    (
        [Parameter(Mandatory=$true)]
        [string]
        $IPAddress
    )

    Import-DscResource -ModuleName xNetworking

    xIPAddress IPAddress
    {
        IPAddress = $IPAddress
        InterfaceAlias = "Ethernet"
        DefaultGateway = "192.168.0.1"
        SubnetMask = "255.255.0.0"
        AddressFamily = "IPv4"
        Ensure = "Present"
    }
}

Now, I have the DSC Resource Kit waves 1-3 installed and available, and I can use them with no problem, in fact I created a configuration using the xNetworking resource with no issues. When the TestResource.schema.psm1 file is set to the above, the system no longer sees it as a valid resource (Get-DscResource no longer lists it).

If I remove the Import-DscResource line but leave everything else out, it recognizes the resource, but the resource is unusable, as it does not know where to find the xNetworking module. I tried putting the Import-DscResource -ModuleName xNetworking in the configuration .ps1, hoping that the import would trickle down, but still no luck.

Did I miss something in documentation stating that a composite resource can't use the Import-DscResource cmdlet? I don't much see the point of composite resources if you can't use other custom resources in them.

Was it helpful?

Solution

Well, I feel silly. The whole issue was the fact that I was mispelling xNetworking as xNetwroking in my resource. Fixed the stupid, and I fixed my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top