Access Parameter in SetScript member of Script Resource in Desired State Config

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Manish Vyas Manish Vyas 3 years ago.

  • Author
    Posts
  • #16183
    Profile photo of Manish Vyas
    Manish Vyas
    Participant

    Hello,

    Desired State Configuration....

    I have been stuck in Script Resource where i need a Configuration Parameter to be used in member SetScript. Here is what i need to do....

    Configuration MyConfig

    {

    param($MyComputerName)

    Script MyScript

    {

    Write-Verbose "Computer Name is : $MyComputerName"
    }

    GetScript = {}

    TestScript = {}

    }

    while executing above configuration, we are getting null value in $MyComputerName in SetScript. here, are the commands that i have been used.

    MyConfig -MyComputerName localhost

    Start-DscConfiguration -Wait -Verbose -Path ./MyConfig

  • #16210
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, I don't think your structure is right. Your Script item should contain ONLY a GetScript and TestScript section. But both of those are actually OUTSIDE your Script item. The Write-Verbose isn't in a legal location there.

  • #16214
    Profile photo of Manish Vyas
    Manish Vyas
    Participant

    ohhh. Really Sorry..its a typo mistake

    The Correct is...

    Configuration MyConfig

    {

    param($MyComputerName)

    Script MyScript

    {

    SetScript = {
    Write-Verbose "Computer Name is : $MyComputerName"
    }

    GetScript = {}

    TestScript = {return $bool}

    }

You must be logged in to reply to this topic.