Script Resource: Ensure Absent?

Welcome Forums DSC (Desired State Configuration) Script Resource: Ensure Absent?

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 4 years ago.

  • Author
  • #19574

    Michael Craig

    My Achievements

    No Achievements Yet!

    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?



  • #19595

    Don Jones

    My Achievements


    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.

You must be logged in to reply to this topic.

Skip to toolbar