DSC Class-based Resource Module Definition

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 1 year, 10 months ago.

  • Author
    Posts
  • #30036
    Profile photo of Adam Weigert
    Adam Weigert
    Participant

    I have an existing module with all my custom DSC resources (v4) defined in the DSCResources folder.

    I want to write my next one as a v5 class-based dsc resource but include it in my existing module of v4 resources.

    I have the class defined in the file xMyResource.ps1 under DSCResources folder. In the module psm1 file I inline execute (. $PSScriptRoot\DSCResources\xMyResource.ps1) and in the module psd1 file I have DscResourcesToExport = 'xMyResource'. I also updated the PowerShellVersion to 5.0 in the definition.

    Using Get-DscResource -Name xMyResource or -Module xMyModule doesn't show it. What am I missing?

    My understanding based on the TechNet article (https://technet.microsoft.com/en-us/library/dn948461.aspx) is that I can have a module definition that exports one or more DSC resources. The module name doesn't have to match the folder name nor does the resource name have to match the module name.

    Also, can I use a wildcard (*) like the FunctionsToExport property or must I include each DscResourcesToExport definition?

  • #30037
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    The DscResource classes must be in the .psm1 with the current release. Microsoft is aware of this limitation and will hopefully fix it before the Q4 release.

    You must specify the RootModule and DscResourcesToExport keys in your module manifest to make it work.

  • #30038
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator
    {
    # Script module or binary module file associated with this manifest.
    RootModule = '.psm1'
    ...
    # DSC resources to export from this module
    DscResourcesToExport = @('xMyClass1','xMyClass2')
    ...
    }
    
  • #30039
    Profile photo of Adam Weigert
    Adam Weigert
    Participant

    Do you know of a connect issue for this that I could upvote? This is really cumbersome to define class-based DSC resources this way.

  • #30155
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    I have searched Connect but couldn't find a bug report. Do you want to submit one and share on Twitter for everyone to upvote?

You must be logged in to reply to this topic.