Error when I try to apply a .mof that was compiled from a custom resource

With WMF 4.0, I want to create my own xDscResource. The reason is that I want to issue a fixed PowerShell command. I believe using DSC and WMF 4, I must create my own resource to run a PowerShell command.

Here is how I created it:

I copied an xResource folder and renamed it to xBsd. I then issued these four commands:

$name = New-xDscResourceProperty -Name Name -Type String -Attribute key -Description “BSD ID”

$sourcePath = New-xDscResourceProperty -Name SourcePath -Type String -Attribute Write -Description “Source Path”

$ensure = New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet @(“Present”, “Absent”) -Description “Ensure”

$xBsd = New-xDscResource -Name xBsd -Property $name, $sourcePath, $ensure -ModuleName “xBsd” -Path "C:\Program Files\WindowsPowerShell\Modules\All Resources"

Here is my first draft of a configuration (that does compile and creates a .mof file).

Configuration coolConfig {
Import-DscResource -name xBsd
Node nameOfNode {
xBsd MySmbShare
{
Ensure = “Present”
Name = “SMBShare1”
} }
coolConfig -OutputPath .

I get an error when I try to apply the configuration (with start-dscconfiguration):

“The PowerShell provider C:\Program Files\WindowsPowerShell\Modules\All Resources\xBsd\DscResources\xBsd returned results in a format that is not valid. The results from running Test-TargetResource must be boolean value True or False.”

What do I need to do to get my configuration that uses a custom-made DSC resource to invoke a fixed PowerShell script? This error appears to be stopping me.

The error is telling you that the code in your Test-TargetResource function is returning something other than $True or $False. You need to look at the code in the .psm1 file to see what’s going on.

But the commands you issued will have created a new resource, not modified an existing one.

Additionally, you shouldn’t be using the “x” prefix. That was something Microsoft was using, and they’ve stopped. It’s not meaningful.

Also, the commands you issued will have created a resource that has SourcePath and Ensure properties; your config, on the other hand, is reference Name and Ensure. So it’s not lining up to what you created.

Generally speaking, you can’t just copy an existing resource and add stuff to it by running commands. You can certainly add things, but you’d need to do so by coding - remembering also to update the schema MOF. I find it’s often easier to start from scratch, create a new resource, and then if there’s some code I want to re-use from somewhere else, just copy that code into the new resource module.

I started over completely and made sure the variables lined up (with the interactive commands and the configuration that invokes this new DSCResource). I stopped using the “x” in the beginning. I ran three commands:

$driveLetter = New-xDscResourceProperty -Name DriveLetter -Type String -Attribute key -Description “DriveLetter”

$ensure = New-xDscResourceProperty -Name Ensure -Type String -Attribute write -ValidateSet @(“Present”, “Absent”) -Description “Ensure”

$orange = New-xDscResource -Name -Property $driveLetter, $ensure -ModuleName “orange” -Path "C:\Program Files\WindowsPowerShell\Modules\All Resources"

I typed in this .ps1 file:

Configuration orangeZeus
{
Import-DscResource -name orange
Node localhost {
orange nifty
{ Ensure = “Present”
DriveLetter = “x”
}}}
orangeZeus -OutputPath .

I ran the configuration (.ps1 file) above. I then ran one start-dscconfiguration command:

Start-DscConfiguration orangeZeus -Wait -Verbose

The results I got where these:
“The PowerShell provider …\DscResources\orange returned results in a format that is not valid. …results …must be boolean…”

I started over a third time. But I got the same error. What should I do to get around this error? I looked at the .psm1 file. I don’t know what is not a Boolean. I don’t know how to correct this problem.

The solution was to use the “Script with the GetScript, SetScript, and TestScript sections.” I didn’t use the New-xDscResource method afterall.