Manage (add and especially delete) variables from powershell

thibaut.appert's Avatar


15 May, 2017 01:15 PM


We want to manage the variables of VariableSets from powershell as each VariableSet will probably contain several hundred variables (for only one environment, we could have up to 30 of them so imagine the number of variables to manage...).

You provide examples of adding and updating variables but I want to be able to delete all variables of a VariableSet to make sure I can import them again from our verified source. I didn't find a way to delete variables, only VariableSet (which I want to avoid)...

Could you help me on this ?


  1. Support Staff 1 Posted by Dalmiro Grañas on 15 May, 2017 07:01 PM

    Dalmiro Grañas's Avatar

    Hi Thibaut,

    Thanks for reaching out! You should be able to do this using Octoposh:

    Let me know if that works for you.


  2. 2 Posted by thibaut.appert on 16 May, 2017 08:22 AM

    thibaut.appert's Avatar

    Hi Dalmiro,

    Thanks it works. I didn't use OctoPosh directly because I had already written some scripts and I didn't want to start over again but it's a great source of inspiration ! ;)

    I only used
     - $variableSet.Variables.clear()
     - $repository.VariableSets.Modify($variableSet)

    One thing though, I had to change one piece of code to work: $variableSet.Variables.clear() instead of $variableSet.Resource.Variables.clear(). I'm using Octopus 3.12.0 and Octopus.Client 4.15.3 for info.


  3. Support Staff 3 Posted by Dalmiro Grañas on 16 May, 2017 10:09 PM

    Dalmiro Grañas's Avatar

    Hi Thibaut,

    Glad to hear its working :).

    That makes sense. If you use the client through Octoposh, you'll need to use $variableSet.Resource.Variables.clear(), but if you use it raw from Powershell, $variableSet.Variables.clear() would be enough.

    If you are going to keep using powershell scripts to talk to the Octopus API, I definitely encourage you to try Octoposh. Next time, before you start writing a new script, ask in the Project's Gitter channel if there isn't something in Octoposh for what you are trying to do already and I'll let you know :)


  4. thibaut.appert closed this discussion on 14 Jun, 2017 02:49 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac