Puts Octopus on/off maintenance mode
   Puts Octopus on/off maintenance mode
   Set-OctopusMaintenanceMode -On

   Set Maintenance mode ON
   Set-OctopusMaintenanceMode -Off

   Set Maintenance mode OFF
   Github project:
   QA and Cmdlet request:

function Set-OctopusMaintenanceMode
        # Octopus maintenance mode switch. Accepts values "ON" or "OFF"

        # Forces cmdlet to continue without prompting

        $c = New-OctopusConnection
        If ($Mode -eq "ON"){$MaintenanceMode = "True"}

        else {$MaintenanceMode = "False"}

            If (!(Get-UserConfirmation -message "Are you sure you want to set maintenance mode for $Env:OctopusURL to the status: $mode ?")){
                Throw "Canceled by user"
        $body = @{IsInMaintenanceMode=$MaintenanceMode} | ConvertTo-Json
            Write-Verbose "[$($MyInvocation.MyCommand)] Turning maintenance mode $($Mode)"   
            $r = Invoke-WebRequest -Uri "$Env:OctopusURL/api/maintenanceconfiguration" -Method PUT -Headers $c.header -Body $body -UseBasicParsing -Verbose:$false
            write-error $_
        Write-Verbose "[$($MyInvocation.MyCommand)] HTTP request to set Maintenance mode $Mode returned code $($r.statuscode)"
        if($r.statuscode -eq 200){
            Return $True
            Return $false