Author Posts

April 9, 2015 at 2:22 am

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 ?

April 9, 2015 at 3:39 am

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?

April 9, 2015 at 4:51 am

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 .

April 9, 2015 at 4:56 am

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.

April 9, 2015 at 5:52 am

Thanks Don ,

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