I’m am getting so close to enjoying the ultimate success on my first Custom DSC configuration. So you know that’s when I’m going to get this error.
I’m creating a custom resource using C#. I used xDscResource to generate the mof and file structure, and then plugged my dll into it. When I try to run the configuration using Start-DscConfiguration, I get the following message:
The command Test-TargetResource of the PS module MongoDbServiceConfiguration does not implement the write property
Ensure mentioned in the corresponding MOF schema file C:\Program Files\WindowsPowerShell\Modules\cTOPAZConfig\DscResour
ces\MongoDbServiceConfiguration\MongoDbServiceConfiguration.schema.mof. All write paramenters mentioned in the schema
file must be implemented by the command Test-TargetResource.
+ CategoryInfo : InvalidOperation: (root/Microsoft/…gurationManager:String) , CimException
+ FullyQualifiedErrorId : WriteParameterNotImplemented
+ PSComputerName : localhost
I used the following to create the xDscResourceProperty:
$Ensure = New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet "Present","Absent"
and then this to create the resource (I defined all the properties using New-xDscResourceProperty, but am trying to focus on the problem-child):
New-xDscResource -Name "MongoDbServiceConfiguration" -Property $ConfigFilePath,$MongoDbExePath,$MongoDbDatabasePath,$Ensure,$HasSecureMongoDb,$Username,$Password,$IsEncrypted,$MongoDbExecutableName,$MongoDbShellName -FriendlyName "XXXXXXXXMongoDbConfig" -ClassVersion 1.0 -Path "C:\Temp\Modules\cXXXXXConfig"
I’ve gotten similar errors after making it required, and I even tried to remove the Value map to see if it would line up, as I suspect that’s where the issue is. However I continue to get the error, so I’m pretty sure I need way to declare “ValueMap” in the schema.mof and a way to declare the exact same thing in the code.
Schema.mof:
[ClassVersion("1.0"), FriendlyName("XXXXXMongoDbConfig")] class MongoDbServiceConfiguration : OMI_BaseResource { [Key] String ConfigFilePath; [Required] String MongoDbExePath; [Required] String MongoDbDatabasePath; [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write] Boolean HasSecureMongoDb; [Write] String Username; [Write] String Password; [Write] Boolean IsEncrypted; [Write] String MongoDbExecutableName; [Write] String MongoDbShellName; };
Property implementation in C#:
[OutputType(typeof(System.Collections.Hashtable))] [Cmdlet(VerbsCommon.Get, "TargetResource")] public class GetTargetResource : PSCmdlet { [Parameter( Mandatory = false )] [ValidateSet("Present", "Absent", IgnoreCase = true)] public string Ensure { get; set; } = "Present";
Any ideas? The code is working as a standalone cmdlet (I’ve got another question about that in a separate thread) as well as running nicely in nUnit tests in C#.