This project is read-only.

Script Parameters: Hash table

Mar 27, 2013 at 11:18 PM
I am wondering if it is possible to pass a hashtable as a Script Parameter defined in the DeploymentMappings.xml?

In powershell it is done via
$VariableName = @{"Key1" = "Value1"; "Key2" = "Value2"}

However whenever I set this up in the DeploymentMappings.xml it does not seem to be parsed correctly. I have tried the following:
<ScriptParameter name="VariableName" value='@{"Key1" = "Value1"; "Key2" = "Value2"}' />
<ScriptParameter name="VariableName" value="@{&quot;Key1&quot; = &quot;Value1&quot;; &quot;Key2&quot; = &quot;Value2&quot;}" />
Mar 28, 2013 at 11:40 PM
Script parameters are always passed as strings.

You could either:
  1. Early in your script, take the string representation and parse it as a hashtable, eg: $hashtable = Invoke-Expression -Command "DATA { $parameterName }"
  2. Fork the TFS Deployer source to identify hashtable parameters and have it do the parsing to a real hashtable first before calling the script.
Apr 2, 2013 at 12:01 AM
With a bit of trial and error I got this to work. jstangroome is right the params are always passed in as strings however when I passed in a string with new line constants in it:
<ScriptParameter name="StringVar" value="Key1 = Value1 `n Key2 = Value2" />
they were not picked up correctly in the script. So I was unable to convert them to a hash table like so.
$HashTableVar = ConvertFrom-StringData -StringData $StringVar
So I ended up doing a hack and replacing the new line with a comma to pass it in to the script. Then once in the script I replaced the comma with the new line again and then fed it into the conversion and it works
<ScriptParameter name="StringVar" value="Key1 = Value1,Key2 = Value2" />
$HashTableVar = ConvertFrom-StringData -StringData $StringVar.Replace(",", "`n")