When I define a DSC Resource as a PowerShell class, I should be able to use arbitrary names for the properties, so long as they're not one of PowerShell's automatic variables.
PS> Get-DscResource -Module dsc-reproImplementationDetail : ClassBasedResourceType : ReproInvalidName : ReproInvalidFriendlyName :Module : dsc-reproModuleName : dsc-reproVersion : 0.0.1Path : C:\code\dsc-repro\dsc-repro.psd1ParentPath : C:\code\dsc-reproImplementedAs : PowerShellCompanyName : UnknownProperties : {Scope, DependsOn, PsDscRunAsCredential}ImplementationDetail : ClassBasedResourceType : ReproValidName : ReproValidFriendlyName :Module : dsc-reproModuleName : dsc-reproVersion : 0.0.1Path : C:\code\dsc-repro\dsc-repro.psd1ParentPath : C:\code\dsc-reproImplementedAs : PowerShellCompanyName : UnknownProperties : {ConfigurationScope, DependsOn, PsDscRunAsCredential}PS> Get-DscResource -Module dsc-reproMethodInvocationException: Exception calling "ImportClassResourcesFromModule" with "3" argument(s): "Syntax error: At line:4, char:21 Buffer: { [key]string Scope^; }; "Exception : Type : System.Management.Automation.MethodInvocationException ErrorRecord : Exception : Type : System.Management.Automation.ParentContainsErrorRecordException Message : Exception calling "ImportClassResourcesFromModule" with "3" argument(s): "Syntax error: At line:4, char:21 Buffer: { [key]string Scope^;}; " HResult : -2146233087 CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException FullyQualifiedErrorId : CimException InvocationInfo : ScriptLineNumber : 2496 OffsetInLine : 5 HistoryId : -1 ScriptName : C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1 Line : $resourcesFound = [Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache]::ImportClassResourcesFromModule($Module, $Resources, $functionsToDefine) PositionMessage : At C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1:2496 char:5 + $resourcesFound = [Microsoft.PowerShell.DesiredStateConfiguration … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PSScriptRoot : C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7 PSCommandPath : C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1 CommandOrigin : Internal ScriptStackTrace : at ImportClassResourcesFromModule, C:\Users\mikey\OneDrive -Microsoft\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1: line 2496 at Get-DscResource<Begin>, C:\Users\mikey\OneDrive - Microsoft\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1: line 3967 at <ScriptBlock>, <No file>: line 1 TargetSite : Name : ConvertToMethodInvocationException DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.3.6.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35 MemberType : Method Module : System.Management.Automation.dll Message : Exception calling "ImportClassResourcesFromModule" with "3" argument(s): "Syntax error: At line:4, char:21 Buffer: { [key]string Scope^;}; " Data : System.Collections.ListDictionaryInternal InnerException : Type : Microsoft.Management.Infrastructure.CimException NativeErrorCode : Failed ErrorData : OMI_Error StatusCode : 1 TargetSite : Name : DeserializeClassHandle DeclaringType : Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer, Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35 MemberType : Method Module : Microsoft.Management.Infrastructure.dll Message : Syntax error: At line:4, char:21 Buffer: { [key]string Scope^;}; Source : Microsoft.Management.Infrastructure HResult : -2146233088 StackTrace : at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClassHandle(Byte[] serializedData, UInt32& offset, IEnumerable`1 cimClasses, String computerName, String namespaceName, OnClassNeeded onClassNeededCallback, GetIncludedFileContent getIncludedFileCallback) at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClasses(Byte[] serializedData, UInt32& offset, IEnumerable`1 classes, String computerName, StringnamespaceName, OnClassNeeded onClassNeededCallback, GetIncludedFileContent getIncludedFileCallback) at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMofFileBuffer(String mof) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ProcessMofForDynamicKeywords(PSModuleInfo module, ICollection`1 resourcesFound, Dictionary`2 functionsToDefine, CimDSCParser parser, String mof, DSCResourceRunAsCredential runAsBehavior) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ImportKeywordsFromScriptFile(String fileName, PSModuleInfo module, ICollection`1 resourcesToImport, ICollection`1 resourcesFound, Dictionary`2 functionsToDefine, List`1 errorList, IScriptExtent extent) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadPowerShellClassResourcesFromModule(PSModuleInfo primaryModuleInfo, PSModuleInfo moduleInfo, ICollection`1resourcesToImport, ICollection`1 resourcesFound, List`1 errorList, Dictionary`2 functionsToDefine, Boolean recurse, IScriptExtent extent) at CallSite.Target(Closure, CallSite, Type, PSModuleInfo, List`1, Dictionary`2) Source : System.Management.Automation HResult : -2146233087 StackTrace : at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo) at CallSite.Target(Closure, CallSite, Type, PSModuleInfo, List`1, Dictionary`2) at System.Management.Automation.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)CategoryInfo : NotSpecified: (:) [], MethodInvocationExceptionFullyQualifiedErrorId : CimExceptionInvocationInfo : ScriptLineNumber : 2496 OffsetInLine : 5 HistoryId : -1 ScriptName : C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1 Line : $resourcesFound = [Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache]::ImportClassResourcesFromModule($Module, $Resources, $functionsToDefine) PositionMessage : At C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1:2496 char:5 + $resourcesFound = [Microsoft.PowerShell.DesiredStateConfiguration … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PSScriptRoot : C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7 PSCommandPath : C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1 CommandOrigin : InternalScriptStackTrace : at ImportClassResourcesFromModule, C:\Users\mikey\OneDrive -Microsoft\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1: line 2496 at Get-DscResource<Begin>, C:\Users\mikey\Documents\PowerShell\Modules\PSDesiredStateConfiguration\2.0.7\PSDesiredStateConfiguration.psm1: line 3967 at <ScriptBlock>, <No file>: line 1
Prerequisites
Steps to reproduce
When I define a DSC Resource as a PowerShell class, I should be able to use arbitrary names for the properties, so long as they're not one of PowerShell's automatic variables.
Create a new folder,
dsc-repro:Define a new PowerShell module manifest,
dsc-repro.psd1, with the following manifest:Define the root module with the following code:
Call
Get-DscResourcefor the module's DSC Resources:Comment out the definition for
ReproInvalid:Call
Get-DscResourcefor the module's DSC Resources:Expected behavior
Actual behavior
Error details
Environment data
Version
2.0.7
Visuals
No response