# Inheritance in class based DSC resources.

**URL:** <https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648>\
**Category:** DSC\
**Created:** [June 16, 2016, 3:23pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648 "2016-06-16T15:23:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 16, 2016, 3:23pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/1 "2016-06-16T15:23:41Z")

</div>

Hey all,

I recently made a post about some of the problems I’ve encountered using the class based resources, wondered if anyone has a solution or have attempted this before?

[http://www.lukegriffith.co.uk/powershell/dsc/2016/06/16/Limitations-of-class-based-dsc-providers.html](http://www.lukegriffith.co.uk/powershell/dsc/2016/06/16/Limitations-of-class-based-dsc-providers.html)

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 20, 2016, 12:21pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/2 "2016-06-20T12:21:37Z")

</div>

DSC Class based resources has no relation with DSC WMI resources and they are not supposed to be registered with WMI. Something else is going on here.  
From the error it appears that your target node either doesn’t have the module ‘inheritedResource’ installed or the version of the module installed is different than 1.0.  
Try the following to troubleshoot on your target node:

1. Get-DscResource -module inheritedResource –\> This should show DSC resource inheritedResource with module version 1.0
2. Import-Module inheritedResource -verbose

If these two are working as expected, can you share your resource?

---

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 22, 2016, 8:44am UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/3 "2016-06-22T08:44:55Z")

</div>

Hey Nitin,

Check out the GitHub project i linked on the blog post, [GitHub - lukegriffith/DSCInheritance: DSC resource superclass/subclass relationship.](https://github.com/lukemgriffith/DSCInheritance)

That has the modules and the psake job that I ran. Following your steps it responds and works fine.

`  
PS wrk:&gt; Get-DscResource -Module InheritedResource

ImplementedAs Name ModuleName Version Properties

* * *

PowerShell InheritedResource InheritedResource 1.0 {Enforce, Ensure, SettingName, DependsOn…}

PS wrk:&gt; import-module InheritedResource -Verbose  
VERBOSE: Loading module from path ‘C:\Users\lukem\Documents\WindowsPowerShell\Modules\InheritedResource\InheritedResource.psd1’.  
VERBOSE: Loading module from path ‘C:\Users\lukem\Documents\WindowsPowerShell\Modules\InheritedResource\InheritedResource.psm1’.  
`

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 22, 2016, 11:50am UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/4 "2016-06-22T11:50:51Z")

</div>

I tried this resource with the following test configuration on WMF 5.0 RTM build and it executed successfully. Are you using WMF 5.0 pre production or WMF 5.0 RTM?

```
configuration foo
{
	param(
		[string] $settingsName
	)
	import-dscresource -module InheritedResource
	
	$guidValue = [guid]::NewGuid()
	
	InheritedResource r1
        {
		settingName=$settingsName
		guid=$guidValue
		Enforce= "Always"
		Ensure = "Present"
         }
}

foo -settingsName "NewSetting"

PS C:\Users\duser1\Desktop> Start-DscConfiguration -path foo -wait -Verbose
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' =
SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer COM12R25RTM01 with user sid
S-1-5-21-2800768176-829124343-4290817346-1106.
VERBOSE: [COM12R25RTM01]: LCM: [Start Set]
VERBOSE: [COM12R25RTM01]: LCM: [Start Resource] [[InheritedResource]r1]
VERBOSE: [COM12R25RTM01]: LCM: [Start Test] [[InheritedResource]r1]
VERBOSE: [COM12R25RTM01]: LCM: [End Test] [[InheritedResource]r1] in 0.1560 seconds.
VERBOSE: [COM12R25RTM01]: LCM: [Skip Set] [[InheritedResource]r1]
VERBOSE: [COM12R25RTM01]: LCM: [End Resource] [[InheritedResource]r1]
VERBOSE: [COM12R25RTM01]: LCM: [End Set]
VERBOSE: [COM12R25RTM01]: LCM: [End Set] in 0.4380 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.557 seconds`
```

---

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 22, 2016, 12:36pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/5 "2016-06-22T12:36:55Z")

</div>

I’ve managed to test on both the below revisions.

Major Minor Build Revision

* * *

5 0 10586 117

Major Minor Build Revision

* * *

5 0 10586 122

Originally I tested on a Win 10 machine, now testing on 2012 r2 core I’m getting a slightly different error.

`  
PS C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\> Invoke-psake -buildFile .\build.ps1 -taskList Integrate  
psake version 4.6.0  
Copyright (c) 2010-2014 James Kovacs & Contributors

cmdlet Get-Credential at command pipeline position 1  
Supply values for the following parameters:  
Credential  
Executing Deploy

Name Used (GB) Free (GB) Provider Root C

* * *

Target FileSystem \srv\c$\Program Files\WindowsPo…  
VERBOSE: Performing the operation “Copy Directory” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules”.  
Copy-Item : An item with the specified name \srv\c$\Program Files\WindowsPowerShell\Modules\Modules already exists.  
At C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\build.ps1:34 char:9

- 

```
    Copy-Item -Path $_.FullName -Destination Target: -Verbose -R ...

```

- 

```
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```

  - CategoryInfo : ResourceExists: (\srv\c$\Progra…Modules\Modules:String) [Copy-Item], IOException
  - FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.CopyItemCommand

VERBOSE: Performing the operation “Copy Directory” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules\Base Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules\Base”.  
VERBOSE: Performing the operation “Create Directory” on target “Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules\Base”.  
VERBOSE: Performing the operation “Copy File” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules\Base\Base.psd1 Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules\Base\Base.psd1”.  
VERBOSE: Performing the operation “Copy File” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules\Base\Base.psm1 Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules\Base\Base.psm1”.  
VERBOSE: Performing the operation “Copy Directory” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules\InheritedResource Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules\InheritedResource”.  
VERBOSE: Performing the operation “Create Directory” on target “Destination: \srv\c$\Program Files\WindowsPowerShell\Modules\Modules\InheritedResource”.  
VERBOSE: Performing the operation “Copy File” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules\InheritedResource\InheritedResource.psd1 Destination: \srv\c$\Program  
Files\WindowsPowerShell\Modules\Modules\InheritedResource\InheritedResource.psd1”.  
VERBOSE: Performing the operation “Copy File” on target “Item: C:\Users\lukem\OneDrive\Documents\GitHub\DSCInheritance\Modules\InheritedResource\InheritedResource.psm1 Destination: \srv\c$\Program  
Files\WindowsPowerShell\Modules\Modules\InheritedResource\InheritedResource.psm1”.  
Executing Integrate

LastWriteTime : 22/06/2016 18:59:46  
Length : 2058  
Name : srv.mof

VERBOSE: Perform operation ‘Invoke CimMethod’ with following parameters, ‘‘methodName’ = SendConfigurationApply,‘className’ = MSFT\_DSCLocalConfigurationManager,‘namespaceName’ = root/Microsoft/Windows/DesiredStateConfiguration’.  
VERBOSE: An LCM method call arrived from computer SRV with user sid S-1-5-21-428108033-3095240199-1711482074-500.  
VERBOSE: [SRV]: LCM: [Start Set]  
VERBOSE: [SRV]: LCM: [End Set]  
Error: 22/06/2016 18:59:47:

- 

```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [] Exception: Importing module InheritedResource failed with error - The specified module 'Base' was not loaded because no valid module file was found in any module directory.

```

`

---

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 22, 2016, 12:41pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/6 "2016-06-22T12:41:17Z")

</div>

Some output from SRV

[srv]: PS C:\Users\Administrator\Documents\> Get-DscResource -Module InheritedResource

ImplementedAs Name ModuleName Version Properties

* * *

PowerShell InheritedResource InheritedResource 1.0 {Enforce, Ensure, SettingName, Depend…

[srv]: PS C:\Users\Administrator\Documents\> Get-Module -ListAvailable | ? {$_.Name -like “Inheri\*” -or $_.Name -eq “Base”}

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

```

ModuleType Version Name ExportedCommands

* * *

Script 1.0 Base  
Script 1.0 InheritedResource

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 22, 2016, 12:46pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/7 "2016-06-22T12:46:19Z")

</div>

I also tested it with version 5.0.10586.117, so at least we can do testing on similar environment.  
Can you try the sample I pasted using InheritedResource as that worked for me using the same build?  
If that works then can you share your generated mof file and I will try to find the root cause of this issue at my end.

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 22, 2016, 12:48pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/8 "2016-06-22T12:48:18Z")

</div>

Get-DScResource is supposed to show the resources from both InheritedResource and Base. Somehow it is not detecting the resources from Base.

PowerShell Base Base 1.0 {Enforce, Ensure, guid, DependsO…  
PowerShell InheritedResource InheritedResource 1.0 {Enforce, Ensure, guid, SettingN…

---

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 22, 2016, 12:52pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/9 "2016-06-22T12:52:50Z")

</div>

Heres the MOF that i generated on revision 177.

Something curious I’ve found, on Base i specifically chose not to export the DSC resource from the module, as it caused InheritedResource not to be discovered. I’ve just updated the psd1 for base to export the resource and now I cannot get InheritedResource from the Get-DscResource command.

/\*  
@TargetNode=‘localhost’  
@GeneratedBy=Administrator  
@GenerationDate=06/22/2016 19:01:47  
@GenerationHost=SRV  
\*/

instance of InheritedResource as $InheritedResource1ref  
{  
ResourceID = “[InheritedResource]r1”;  
Enforce = “Always”;  
Ensure = “Present”;  
SourceInfo = “::10::2::InheritedResource”;  
SettingName = “NewSetting”;  
ModuleName = “InheritedResource”;  
ModuleVersion = “1.0”;

ConfigurationName = “foo”;

};  
instance of OMI\_ConfigurationDocument

```
                {

```

Version=“2.0.0”;

```
                    MinimumCompatibleVersion = "1.0.0";

                    CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};

                    Author="Administrator";

                    GenerationDate="06/22/2016 19:01:47";

                    GenerationHost="SRV";

                    Name="foo";

                };

```

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 22, 2016, 1:00pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/10 "2016-06-22T13:00:44Z")

</div>

On my machine both Base and InheritedResource are exporting DSC Resource and Get-DscResource is able to discover them. Let us make sure that I am using exactly same bits as yours for testing.

```
PS C:\Users\duser1\Desktop> dir C:\Windows\system32\DscCore.dll| select VersionInfo| fl *

VersionInfo : File: C:\Windows\system32\DscCore.dll
              InternalName: DscCore.dll
              OriginalFilename: DscCore.dll.mui
              FileVersion: 10.0.10586.117 (th2_release.160212-2359)
              FileDescription: DSC
              Product: Microsoft® Windows® Operating System
              ProductVersion: 10.0.10586.117
              Debug: False
              Patched: False
              PreRelease: False
              PrivateBuild: False
              SpecialBuild: False
              Language: English (United States)

PS C:\Users\duser1\Desktop> $PSVersionTable

Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.34003
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS C:\Users\duser1\Desktop> Get-DscResource -Name in*

ImplementedAs Name ModuleName Version Properties
------------- ---- ---------- ------- ----------
PowerShell InheritedResource InheritedResource 1.0 {Enforce, Ensure, guid, SettingN...

PS C:\Users\duser1\Desktop> Get-DscResource -Name base

ImplementedAs Name ModuleName Version Properties
------------- ---- ---------- ------- ----------
PowerShell Base Base 1.0 {Enforce, Ensure, guid, DependsO...
```

---

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 22, 2016, 1:01pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/11 "2016-06-22T13:01:26Z")

</div>

Infact, my deploy script was wrong for this server.

SRV has managed to run the DSC resource, so it looks like it potentially could be a problem with the 5.0.10586.122 release.

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 22, 2016, 1:03pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/12 "2016-06-22T13:03:50Z")

</div>

I will check on build 122 in a while and let you know my findings.

---

<div class="post-metadata">

**Author:** ![luke-griffith](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@luke-griffith](https://forums.powershell.org/u/luke-griffith)\
**Post date:** [June 22, 2016, 1:06pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/13 "2016-06-22T13:06:20Z")

</div>

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![nitin-gupta](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/nitin-gupta/32/344_2.png) [@nitin-gupta](https://forums.powershell.org/u/nitin-gupta)\
**Post date:** [June 24, 2016, 1:21pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/14 "2016-06-24T13:21:12Z")

</div>

Luke, it seems like you are copying modules in a non expected folder (notice extra _Modules_ in the path)

[srv]: PS C:\Users\Administrator\Documents\> Get-Module -ListAvailable | ? {$_.Name -like “Inheri\*” -or $_.Name -eq “Base”}

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

ModuleType Version Name ExportedCommands  
———- ——- —- —————-  
Script 1.0 Base  
Script 1.0 InheritedResource

Can you try to copy the modules directly under Modules folder and try again.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:16pm UTC](https://forums.powershell.org/t/inheritance-in-class-based-dsc-resources/6648/15 "2024-05-16T21:16:54Z")

</div>


