Common helper functions across DSC resources

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Arie H Arie H 1 month, 1 week ago.

  • Author
    Posts
  • #55757
    Profile photo of Sameer Kumar
    Sameer Kumar
    Participant

    Hello,
    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
    Profile photo of Sameer Kumar
    Sameer Kumar
    Participant

    Figured out. Never mind. Thanks!

  • #55792
    Profile photo of Sameer Kumar
    Sameer Kumar
    Participant

    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
    Profile photo of Arie H
    Arie H
    Participant

    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.