Author Posts

June 16, 2016 at 8:53 pm

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

June 20, 2016 at 5:51 pm

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?

June 22, 2016 at 2:14 pm

Hey Nitin,

Check out the GitHub project i linked on the blog post, 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:\> Get-DscResource -Module InheritedResource

ImplementedAs Name ModuleName Version Properties
————- —- ———- ——- ———-
PowerShell InheritedResource InheritedResource 1.0 {Enforce, Ensure, SettingName, DependsOn...}

PS wrk:\> 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'.
`

June 22, 2016 at 5:20 pm

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`

June 22, 2016 at 6:06 pm

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.
`

  • This reply was modified 2 years, 3 months ago by  Luke Griffith.

June 22, 2016 at 6:11 pm

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

June 22, 2016 at 6:16 pm

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.

June 22, 2016 at 6:18 pm

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...

June 22, 2016 at 6:22 pm

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";

};

June 22, 2016 at 6:30 pm

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...

June 22, 2016 at 6:31 pm

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.

June 22, 2016 at 6:33 pm

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

June 22, 2016 at 6:36 pm

Thanks for your help.

June 24, 2016 at 6:51 pm

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.