Get-targetresource and it's returndata

Welcome Forums DSC (Desired State Configuration) Get-targetresource and it's returndata

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #34996

    Participant
    Points: 0
    Rank: Member

    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?

  • #34998

    Keymaster
    Points: 1,674
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #35004

    Member
    Points: 0
    Rank: Member

    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.

  • #35007

    Participant
    Points: 0
    Rank: Member

    perfect. Thanks for the feedback!

The topic ‘Get-targetresource and it's returndata’ is closed to new replies.