Trying to get Powershell DSC to work

So I new to this product as of yesterday, and not much of a developer as I am an infrastructure guy, so go easy on me. I also apologize ahead of time if I am asking a dumb question.
Like I stated before, I am not a developer, but I can see the immediate usefulness of this product for PowerShell and DSC, and so far I am loving it! I seem to not have too much issue with any straight PowerShell scripts, but when I try a DSC configuration, I am having problems with the pathing. I cannot seem to find a variable that works the same as %~dp in batch. I have tried doing a few variables that I found, and had them written to a txt file as I have not found a better way to do it yet. I have tried:
$y = $OctopusParameters[‘Octopus.Tentacle.Agent.ProgramDirectoryPath’]

and that didn’t write anything, interestingly enough it did append the C:\ drive as part of the path when I tried to a set-dscconfigurationmanager.

Bottom line, is has anyone had any luck using this with powershell DSC or more importantly, what am I doing wrong?

Hi Jonathan,

Thanks for getting in touch. All the variables that come from the dictionary $OctopusParameters are only available within the context of the deployment, and not through a regular Powershell scripts like the one that runs with DSC.

The question here is which value are you trying to get and why. The value that that variable would usually return is the path where the Tentacle is installed on the machine, which usually is C:\Program Files\Octopus Deploy\Tentacle\. If you’d like to get that same value from regular PS script (not from a deployment), you could get it from the Windows registry using this snippet.

$key = get-itemproperty "HKLM:\SOFTWARE\Octopus\Tentacle"

*This would of course return always the right value depending on where the Tentacle was installed on the machine, which shouldn’t necessary always be C:\Program Files\Octopus Deploy\Tentacle*

Hope that helps,

Thank you.

I am aware that the $OctopusParameters are present only during a deployment., and I assume through the script console as well? So what I am trying to do is configure the DSC Local Configuration Manager (LCM). I just wanted to change this setting just to see if I can get it to work. 6 Hours later, and many, many attempts, I have decided I might need some help :slight_smile:

$Node= $OctopusParameters[‘Octopus.Machine.Name’]

configuration SetPushMode$Node
Node $Node
RefreshMode = 'Push’
ConfigurationMode = ‘ApplyAndAutoCorrect’


$y = $OctopusParameters[“Package.InstallationDirectoryPath”]

Set-DscLocalConfigurationManager -Path “$y\SetPushMode_$Node” -Verbose -ComputerName $Node

::: Update, I finally got it to work, mostly because of my own fault. Sometimes it’s better to walk away from it and sleep on the issue, seems to work more often than not! I was able to push out a DSC LCM update to a machine, woot! I am going to post some other things as I continue to use this for DSC to help others. Thanks and keep up the good work!

Glad to hear you sorted it out!

If you write a blog post, please come back here and post the link so the rest of the community can learn from your experience :slight_smile:


For anyone interested in DSC and Octopus together, we wrote a blog post here:

Octopus, the missing UI for PowerShell DSC