Public/FeatureFlags/Disable-JIMFeature.ps1
|
# Copyright (c) Tetron Limited. All rights reserved. # Licensed under the Tetron Commercial License. See LICENSE file in the project root. function Disable-JIMFeature { <# .SYNOPSIS Disables a JIM feature flag. .DESCRIPTION Switches off a feature flag by key. Disabling never requires acknowledgement, whatever the flag's tier. An audit activity is created for each change. Supports ShouldProcess; use -WhatIf or -Confirm to preview or confirm the operation. .PARAMETER Name The key of the flag to disable, such as "Features.SomeInDevelopmentFeature". A flag piped from Get-JIMFeature binds by its Key. .PARAMETER PassThru Returns the feature flag as updated. .OUTPUTS With -PassThru, the feature flag as updated; otherwise nothing. .EXAMPLE Disable-JIMFeature -Name "Features.SomeInDevelopmentFeature" Disables the named feature flag. .EXAMPLE Get-JIMFeature -IncludeInDevelopment | Disable-JIMFeature Disables every feature flag currently returned (Preview and In Development). .LINK Get-JIMFeature Enable-JIMFeature #> [CmdletBinding(SupportsShouldProcess)] [OutputType('JIM.FeatureFlagDto')] param( [Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)] [Alias('Key')] [string]$Name, [switch]$PassThru ) process { # Check connection first if (-not $script:JIMConnection) { Write-Error "You are not connected to JIM. Run Connect-JIM -Url <your JIM URL> to authenticate, then try again." return } if ($PSCmdlet.ShouldProcess($Name, "Disable feature flag")) { Write-Verbose "Disabling feature flag: $Name" try { $body = @{ enabled = $false } $response = Invoke-JIMApi -Endpoint "/api/v1/features/$Name" -Method 'PUT' -Body $body Write-Verbose "Disabled feature flag: $Name" if ($PassThru) { $response } } catch { Write-Error "Failed to disable feature flag '$Name': $_" } } } } |