Author Posts

February 8, 2016 at 10:58 am

I'm writing a module/resource that is a little more unique than others I've written and because of this, I'm finding the format of the return data that I'd like to get back from get-targetresource to be unique even when compared to the parameters of the resource. But it then occurred to me that if the return data doesn't match the parameters then it's not as predictable and I might break something. Which leads to the question:

Is it "safe" to treat "get-targetresource" as effectively a reporting-only function and thus while it may share the same universal parameter inputs it might return some unique output?

Quick and dirty example: Lets say while it's not a parameter I'd use in my set-, I'd like to report back on a property of an object (like the creator of the file)? Would the lack of an "owner" parameter be a problem if "owner" made it back in the returndata of a get-targetresource?

February 8, 2016 at 11:24 am

Yeah, generally, it's safe to treat Get-TargetResource as reporting-only. The LCM, under normal operation, really relies on Test- and Set-, to the point where a lot of early v4 resources didn't even implement Get- because v4 didn't use it.

That said, you should keep comparisons in mind. I should be able to take the output of Get- and run a Diff against an identically structured "desired" object, and either have differences or no differences. So while it wouldn't cause a problem for the LCM, it might cause a problem for a human who had different expectations.

February 8, 2016 at 12:10 pm

DSC supports read-only properties for this reason. For example, here's the schema for the built-in Package resource:

[ClassVersion("1.0.0"),FriendlyName("Package")] 
class MSFT_PackageResource : OMI_BaseResource
{
  [write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
  [Key] string Name;
  [required] string Path;
  [Key] string ProductId;
  [write] string Arguments;
  [write,EmbeddedInstance("MSFT_Credential")] string Credential;
  [write] uint32 ReturnCode[];
  [write] string LogPath;
  [read] string PackageDescription;
  [read] string Publisher;
  [read] string InstalledOn;
  [read] uint32 Size;
  [read] string Version;
  [read] boolean Installed;
};

All of those properties marked as [read] can be returned in Get-TargetResource, but are not used anywhere else.

February 8, 2016 at 12:29 pm

perfect. Thanks for the feedback!