DSC Resource Global Variable

This topic contains 4 replies, has 2 voices, and was last updated by  Mariusz Serwin 2 years, 4 months ago.

  • Author
    Posts
  • #24096

    Mariusz Serwin
    Participant

    I'm trying to pass some information from Test-TargetResource to Set-TargetResource using Global Variable but it doesn't work when I run my configuration .

    Can you use Global Variables in DSC Resources ?

  • #24097

    Don Jones
    Keymaster

    Set- and Test- are run at completely different cycles, so there's not a reliable way to "share" information. And you definitely should not use global variables. What is it you're trying to do, more specifically?

  • #24100

    Mariusz Serwin
    Participant

    I'm modifying Smbshare resource and I'm trying to test what user/permission should be removed from the share and assign it to global variable and pass it to set-TargetResource so then the user/permissions can be added or removed .

    So I think the only option would be to implement validation in Set-TargetResoruce before making any changes .

  • #24101

    Don Jones
    Keymaster

    The right design pattern is probably to have private functions that do all the "work." Those can then be called either by Test- or Set- as needed. Since there's obviously overlap in what Test- and Set- do, moving the functionality to separate functions lets you modularize your code, and maintain granularity.

  • #24103

    Mariusz Serwin
    Participant

    Thanks Don ,

    I will create private function as you mentioned , that's the best way .

You must be logged in to reply to this topic.