Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Hash table returned from Get-TargetResource must contain all properties in the schema.mof #318

Closed
johlju opened this issue Sep 10, 2017 · 10 comments

Comments

@johlju
Copy link
Contributor

johlju commented Sep 10, 2017

I trying to figure out this question; Must the Get-TargetResource always return a hash table containing all the properties in the scheme.mof?

I think @kwirkykat might have mention this somewhere - but finding that is like a needle in a hay stack.

I can't find this in any guideline or common test. I can only find this text.

In the Get-TargetResource ... This function must return a hash table that lists all the resource properties as keys and the actual values of these properties as the corresponding values.
https://docs.microsoft.com/en-us/powershell/dsc/authoringresourcemof#writing-the-resource-script

So if this is true, then we should have a common test for it. Because then I have this problem in many resources!

@johlju
Copy link
Contributor Author

johlju commented Sep 10, 2017

@kwirkykat @mbreakey3 (or anyone else) can you answer this question?

@scottleyg
Copy link

scottleyg commented Sep 10, 2017 via email

@bgelens
Copy link
Contributor

bgelens commented Sep 11, 2017

@johlju It's in the official DSC docs

In the Get-TargetResource function implementation, use the key resource property values that are provided as parameters to check the status of the specified resource instance. This function must return a hash table that lists all the resource properties as keys and the actual values of these properties as the corresponding values.

@johlju
Copy link
Contributor Author

johlju commented Sep 11, 2017

Yes, thats the same paragraph I quoted in the initial issue comment.
I just wanted to make sure that the text was accurate before changing the guidelines and before trying to writing a common test to warn about missing properties in the hash table.
To many resources have this problem to fail the tests, at least at this point.

@randomnote1
Copy link

@johlju, thanks for raising the question/issue. I was looking at this today and realized there currently isn't a common test for this.

@johlju
Copy link
Contributor Author

johlju commented Sep 12, 2017

@kwirkykat Is it okay that I add this to the best practices guideline and also write a common test for this (that will write warnings for the time being)?

@ld0614
Copy link
Contributor

ld0614 commented Sep 17, 2017

While I agree that in most situations the Get-TargetResource should return actual values I think its important that the guidance is clarified for resources which include Add and Remove Properties (Such as the Group Resource) and resources with specific Credential objects as these don't lend themselves to returning useful values.

A simple way to handle with would be to allow test opt-outs for specific parameters against a known set of criteria in a similar way that [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "global:DSCMachineStatus")] is allowed for calling a reboot.

@johlju
Copy link
Contributor Author

johlju commented Apr 18, 2018

I suggest we move this issue to DscResource.Tests so that we can add a test for this.

@johlju
Copy link
Contributor Author

johlju commented Apr 20, 2018

I have created an issue in DscResource.Tests which referencing this issue. Closing this issue here, and suggest moving any further discussion to the issue PowerShell/DscResource.Tests#220.

@johlju johlju closed this as completed Apr 20, 2018
@johlju
Copy link
Contributor Author

johlju commented Aug 9, 2018

For reference, this error is output when trying to return a property that does not exist in the schema. Unfortunately there is apparently not the similiar check when the hash table is not returning all properties in the schema.

Get-DscConfiguration : The PowerShell DSC resource  returned results that are not valid from Get-TargetResource. The XYZXYZ key is not a valid property in the corresponding DSC resource schema file. The results from 
Get-TargetResource must be in a Hashtable format. The keys in the Hashtable must be the same as the properties in the corresponding DSC resource schema file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants