I'm starting to use the script resource quite a bit, and after writing a few resources I realize that there is no "Ensure = Present/Absent"
My question is, how are people handling this?
I'm trying to write my DSC script so that I can set a variable at the top:
The idea being that I can use the same script to generate a mof to build a server, and also to generate a mof to revert a server.
Has anyone else tackled this already?
I'm thinking I could use my $Action as a switch statement in both the Test and Set actions to either ensure the result is present or absent.
Q: In general are people doing this, or is this a waste of time?
Correct. Not all resources provide an "Ensure" setting; the Script Resource only provides Get/Set/Test settings, which are script blocks. If you want something gone, you write a script item that makes sure it's gone. If you want something present, you write a separate script setting to make it present. The downside of script resources is that they're not as easily reusable across situations.
What you probably want to do instead is write a custom resource, as a script module. There, you can definitely define an Ensure setting, and your Get/Set/Test functions can handle it accordingly. What you're trying to do with the script resource is more than it was intended for, and you're going to fight it.
The topic ‘Script Resource: Ensure Absent?’ is closed to new replies.