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

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

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.

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}

}