Update tenant variable value using Powershell

Hi!

Can anyone give me an example of PS script, used for tenant variable value update?

We have a PS script, used for reading tenant variable value, but now we need to change value.

Here is an example of reading script:

##CONFIG MineQ-CPM
$OctopusURI = “” #Octopus URL
$APIKey = “” #Octopus API Key
$TenantID = “” #ID of the tenant you want to get the variable from.
$VariableName = “DataAPIJson” #Variable name

##PROCESS##
$header = @{ “X-Octopus-ApiKey” = $octopusAPIKey }
$variable = ((invoke-webrequest $OctopusURI//api/tenants/$TenantID/variables -Headers $header).content | ConvertFrom-Json).ProjectVariables.“Projects-246”.variables.“Environments-4”.“f7866b87-e194-4a90-adbe-a4eae705ef86”

echo $variable.value

Or, can you give me an example of webrequest to change an existing variable in tenant?

Thanks in advance.

Hi Vasyl,

Thanks for getting in touch! Looking online and through our public sample script repo, unfortunately I don’t see one specifically designed to update a tenant variable. You can certainly look through those which may provide some inspiration, and our API wiki to look through all of the TenantVariable’s properties. The closest example I came across was one using the Octopus.Client (an open source .NET library designed to make manipulating the REST API easier) which can be referenced in this comment.

I hope this helps get you going! Don’t hesitate to reach out if you have any further questions or concerns going forward. :slight_smile:

Kind regards,

Kenny

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