Skip to content

Instantly share code, notes, and snippets.

@NReilingh
Last active September 24, 2019 06:45
Show Gist options
  • Save NReilingh/f503c556f45f032dd01f9de82f4f0ae0 to your computer and use it in GitHub Desktop.
Save NReilingh/f503c556f45f032dd01f9de82f4f0ae0 to your computer and use it in GitHub Desktop.
DSC Script Resource $using:Key bug
Configuration TestConfig
{
Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
$Key = "My Value"
Node localhost
{
Script TestScript
{
GetScript = {
Write-Verbose "`$Key value is $using:Key"
# NoOp
}
TestScript = {
Write-Verbose "`$Key value is $using:Key"
if ($using:Key -eq 'Credential') {
return $false
} else {
return $true
}
}
SetScript = {
Write-Verbose "`$Key value is $using:Key"
# NoOp
}
}
}
}
TestConfig
@NReilingh
Copy link
Author

Run this script and then inspect the output TestConfig\localhost.mof file. "My Value" is not present.

PowerShell 5.1.18362.145

@kungfoome
Copy link

Changing key to mykey seems to work ok, but i get the same result using key as a variable.

Configuration TestConfig
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

    $myKey = "My Value"

    Node localhost
    {
        Script TestScript
        {
            GetScript = {
                Write-Verbose "`$myKey value is $using:myKey"
                # NoOp
            }
            TestScript = {
                Write-Verbose "`$myKey value is $using:myKey"

                if ($using:myKey -eq 'Credential') {
                    return $false
                } else {
                    return $true
                }
            }
            SetScript = {
                Write-Verbose "`$myKey value is $using:myKey"
                # NoOp
            }
        }
    }
}

TestConfig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment