Variable substitution into index of OctopusParameters

I have a variableset containing certificates for our various environments.
In a custom step template, I ensure that this is present in the local certificate store, before proceeding with other tasks.
I have two versions of the step template, one in which the name of the variable in the set is hardcoded and another which attempts to set this with a variable. The latter doesn’t work.

For Example the below will echo out the thumbprint of the certificate as expected into the log
Write-Host “INFO: Certificate with thumbprint $($OctopusParameters[“WebCertificate.Thumbprint”]) found in the local machine store”

However the below on a process where CeritificateName is set to “WebCertificate” will echo out the correct name, however the thumbprint comes out null.
Write-Host “INFO: Certificate $($CertificateName) with thumbprint $($OctopusParameters[”$($CertificateName).Thumbprint") found in the local machine store"

I did see mention on an older post that the index has to be a single variable so I did also try declaring “$($CertificateName).Thumbprint” into a variable before hand, so it looks like $OctopusParameters[$thumbprint] .Unfortunately this also evaluates as null

I feel I’m missing out on a potentially obvious syntax issue and any assistance would be appreciated as I’d like to avoid hardcoding this and having separate step templates.

Thanks in advance.

Hi Scott,

Thanks for getting in touch! At first I suspected this issue came down to syntax like you were thinking. When I tried running the exact snippet you’ve provided, it pointed out the missing ] after the array index expression (but I suspect this part was just a copy/paste typo).

However after some testing, I think I’ve spotted the issue. Your $CertificateName evaluates to the certificate ID, however the Certificate.Thumbprint gets the thumbprint based on the certificate variable’s name (not its ID) followed by .Thumbprint. This means you could define another variable to the certificate variable’s name and then call that. This is the easiest solution as I’m not exactly a PowerShell expert, but you may have better luck expanding on it. :slight_smile:

These are my two variables (where the value of cert is just the name of my certificate variable):

Using this modified script snippet:

Write-Host "INFO: Certificate $($MyCertificate) with thumbprint $($OctopusParameters["$($cert).Thumbprint"]) found in the local machine store"

Gives us the result I think you’re after.

Let me know if this helps or if you have any further questions moving forward!

Best regards,


Hi Kenny,

Thanks for the reply. It appears I was being daft :smiley:
Certificate name was a local project string which I was then wanting to call the appropriate certificate out of a library set - it makes much more sense to use your approach of pulling the certificate into a local project variable where the scoping/etc is much more visible.

Thanks again

Hi Scott,

Thanks for following up, and you’re very welcome! That’s great to hear that helped. Don’t hesitate to reach out if you have any questions in the future. :slight_smile:

Best regards,


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.