Powershell and Octo API

We have run into a problem with many of our projects where the “Automatically run configuration transform files” box is checked on a whole bunch of steps in a whole bunch of projects and we’re looking for a programmatic way to update each project/step. I have no problem using the API to locate the steps that need to be updated, however, I cannot find any way to actually change the value ($step.Actions.Properties.‘Octopus.Action.Package.AutomaticallyRunConfigurationTransformationFiles’). It seems like there is an action method or something I am missing and I haven’t been able to locate detailed enough documentation to point me in the right direction. The code I am using is below. Any help is appreciated.

Add-Type -Path “C:\Program Files\WindowsPowerShell\Modules\Octoposh\0.6.11\Octopus.Client.dll”
$apiKeyDev = Import-CliXml -Path ‘C:\DevOctoApiKey.xml’ #Octopus DEV API Key
$apiKey = $apiKeyDev.GetNetworkCredential().Password
$OctopusURL = ‘http:///octo’
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURL,$apiKey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$projects = $repository.Projects.FindAll()
foreach($project in $projects)
$deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessId)
foreach ($step in $deploymentProcess.Steps)

		if(($step.Actions.Properties.'Octopus.Action.Package.AutomaticallyRunConfigurationTransformationFiles').Value -eq $True)
            #Something needs to happen here, not sure what :)

	$repository.DeploymentProcesses.Modify($deploymentProcess) | Out-Null 


Hi Steve,

Thanks for getting in touch! You are nearly there. The missing line can look like this:
$step.Actions.Properties.'Octopus.Action.Package.AutomaticallyRunConfigurationTransformationFiles' = New-Object Octopus.Client.Model.PropertyValueResource "False"

One thing to pay attention to here is that $step.Actions will return an object only when there is only one action. In all other cases it will return an array and then this code will fail.

Please, let me know how you go.



Thanks so much Pawel, that works like a charm. I’m going to modify the code to reflect the $steps.Action caveat you mentioned, I’ll post the finished product here for anyone else that might need it.

Thanks again for the quick response! You guys rock!