"Return" Configurations

Welcome Forums DSC (Desired State Configuration) "Return" Configurations

This topic contains 3 replies, has 3 voices, and was last updated by

3 years, 2 months ago.

  • Author
  • #35495

    Topics: 29
    Replies: 125
    Points: 0
    Rank: Member

    Might be a bit of an odd question, but I'm wondering if I can "return" a configuration from a script for use in another script/function when called. Like within a ps1 litterally do something like:

    configuration blahblah {}
    return blahblah

    Then in a separate script be able to go:

    Configuration DesiredConfig {Invoke-Expression configfile.ps1}

    Basically I"m just trying to see if there's a way I can separate my actual configuration from a "compile and and deploy" helper function. Right now I'm calling my configuration with a a simple Invoke-Expression ". $myconfig" but I've read that I should avoid using that method when possible as it risks someone being able to inject extra "unwanted" code. Plus it means I don't _actually_ know the name of the configuration ... I have to hope it's named consistently.

    I might be trying to do "too much", but basically I'm writing a simple function to assist people in just picking their "what and where" and let the function generate the mofs, check-sums, and then push the files out to the appropriate pull servers.

  • #35496

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero


    But you can certainly dot-source scripts, even if they contain configurations.

  • #35506

    Topics: 29
    Replies: 125
    Points: 0
    Rank: Member

    dot source it is, then. Thanks!

  • #35739

    Topics: 5
    Replies: 261
    Points: -19
    Rank: Member

    Just an idea, you can always generate the dsc script based on "what and where" as a file and then run it 😉

The topic ‘"Return" Configurations’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort