Powershell Script for Enable or Disable a Scheduled Trigger

Hi I want to enable or disable an already scheduled trigger automatically by a powershell script as a process in my octopus project. By editing the “$TriggerAPI.IsDisabled = “True””/ $TriggerAPI.IsDisabled = “false” . While trying this I got Method not allowed error. :frowning: Is it possible to edit the trigger state by a post method ? Help me please…

below is the script I have tried.

$TriggerAPI = Invoke-RestMethod -Uri $url -ContentType application/json -Headers @{“X-Octopus-ApiKey”="$octopus_apikey"} -Method Get -Verbose
(Trigger API GET) after changing the value IsDisabled to true or false
Invoke-WebRequest -Uri $url -Method POST -Headers @{“X-Octopus-ApiKey”="$octopus_apikey"} -Body $TriggerAPI .

Hi I changed the POST method to PUT and Its Works for ME .

Below is the working script

$TriggerAPI = Invoke-RestMethod -Uri $url -ContentType application/json -Headers @{“X-Octopus-ApiKey”="$octopus_apikey"} -Method Get -Verbose
$TriggerAPI.IsDisabled = “false” #True to disable
Invoke-RestMethod -Uri $url -ContentType ‘application/json’ -Headers $header -Method PUT -Body ($TriggerAPI | ConvertTo-Json)

Hi Yadukrishnan,

Thanks for getting in touch! That’s great to hear you’ve gotten your script working as expected. I appreciate you letting us know the outcome to help people looking to do the same in the future. Please don’t hesitate to reach out if you have any further questions moving forward. :slight_smile:

Best regards,

Kenny

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