Common helper functions across DSC resources

This topic contains 3 replies, has 2 voices, and was last updated by  Arie H 1 year, 7 months ago.

  • Author
  • #55757

    Sameer Kumar

    Can you please suggest an optimal way to share common functions among multiple DSC resources?
    For instance, I have a logging helper function called "Write-Log" which I need to use from multiple custom DSC resources. So instead of duplicating these kind of logic pieces in multiple places, can I store them in a central place and consume them without repeating myself?
    Thanks for your help!

  • #55777

    Sameer Kumar

    Figured out. Never mind. Thanks!

  • #55792

    Sameer Kumar

    I'm bit confused about the static and dynamic variables used in DSC configurations.
    I am using private helper functions in my DSC resources. Those are being executed ahead of the time which in my opinion is weird.
    For instance in my configuration file i have 2 dsc resources let's say R1 and R2. R2 depends on R1. One of the R2 dsc properties is 'LogMessage' which uses a private function to pull its value instead of a static string. The private function reads a file generated by R1 lets say file1.txt and returns the message string. My script fails stating that the file1.txt doesn't exist. If I remove R2 from the configuration script, it works and file1.txt gets generated.
    What am I missing here?

  • #56342

    Arie H

    When you're saying "R2 depends on R1", is that just your logic or did you actually use the DependsOn property ?

You must be logged in to reply to this topic.