Hashtable input into Powershell Script from Variables?

Hi guys, I’m new to Octopus,

I have an existing powershell function that does what I need from my machine and it is reusable for many different projects. Sounds like an ideal use of your Step template.

In this case I have a few parameters that are fixed which are fine and simple and would make sense to use as simple string parameters. Easy.

However I also want to provide support for any number of custom name/value pairs which I naturally have as a hashtable argument on my powershell. This seems more tricky as parameters are pure strings. Furthermore I expect these name value pairs to be defined as variables. Intrigued by the seeming hashtable/dictionary capability of variables shown here (http://docs.octopusdeploy.com/display/OD/Variable+Substitution+Syntax)… so I was hoping that I could do something like

ScriptVariable[DoISupportX] = "True"
ScriptVariable[WebpageString] = "Hello World"
ScriptVariable[LoginName] = "ServerLogin"
ScriptVariable[LoginPassword] = “letmeinprettyplease”

Of course the password would be a sensitive variable, the
And pass ScriptVariable in somehow to a hashtable parameter on the existing powershell function. I don’t mind if I cant parameterise it and a requirement is that these values must be in the “ScriptVariable” collection.

I can see from that page that I could perhaps fashion something up with an #{each ScriptVariable}…#{/each} block but I wondered if actually this would be available directly as a Hashtable somehow to my powershell script in a simpler way?

Any tips on how I can self-discover this stuff would be welcome! Unfortunately I am not an admin.

Thanks for any advice or tips


Thanks for reaching out. I’m not sure I’m following what you need, most likely cause I haven’t had my 6pm coffee yet :). Are you trying to load variables into Octopus from a Powershell hashtable? If that is the case, I made a script for this a while back that uses a JSON file to inject variables into Octopus. This script is part of the Octoposh module -> https://github.com/Dalmirog/OctoPosh/wiki/Modifying-Variable-Sets

You could create the JSON file using your already existing hashtable, and then pass the file to the Update-OctopusVariableSet cmdlet.

Let me know If this is similar to what you were looking for, or if I totally missed your point.



Hi Dalmiro,

I guess I am asking if, given the variable setup in my last post, there is a way that octopus automatically provides my “ScriptVariable” variable collection as a hashtable for me to then pass directly to my powershell function parameter.

I know octopus provides each variable inside a hashtable itself, but these “collection” types seem to lend themselves to a nested hashtable.

Of course I guess I could loop through the variables available in the powershell environment to build my own hashtable to pass in based on some pattern to find, but I was wondering if octopus would already have something that would save me that small amount of work.


Hi Brett,

Now I understand your question. There’s no built-in way to do this. Your gonna have to go the Powershell-way with the loop.