Hi Sreekanth,
I’ve spent sometime looking at this and the following script will retrieve a variable set, and allow you to change the value of a variable based on the variable name.
# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll'
$apikey = 'API-XJF3OZREHTNRYTCI0BBUHI9N8S' # Get this from your profile
$octopusURI = 'http://localhost' # Your server address
$libraryVariableSetId = "LibraryVariableSets-1" # Get this from /api/libraryvariablesets
$variableName = "Variable name" # Name of the current variable
$variableValue = "Test" # New value for the variable
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$libraryVariableSet = $repository.LibraryVariableSets.Get($libraryVariableSetId);
$variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId);
$variables.AddOrUpdateVariableValue($variableName,$variableValue)
$repository.VariableSets.Modify($variables)
It is fairly basic at this point so has a flaw where if there are multiple values attached to a variable, it will update all of them to the same value. If you need to modify this kind of variable then you will need to specifically select the one you want to modify prior to the AddOrUpdateVariableValue command.
I hope this helps.
Regards,
Paul