Modules/businessdev.ALbuild.Environments/Public/Remove-BcEnvironment.ps1

function Remove-BcEnvironment {
    <#
    .SYNOPSIS
        Removes an ALbuild Business Central environment and its Traefik configuration (licensed).
 
    .PARAMETER Name
        Environment / container name.
 
    .PARAMETER TraefikConfigFolder
        Folder containing the environment's Traefik dynamic config (<Name>.json) to delete.
 
    .PARAMETER DockerExecutable
        The Docker executable to use (default 'docker').
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param(
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [string] $Name,
        [string] $TraefikConfigFolder,
        [string] $DockerExecutable = 'docker'
    )

    process {
        Assert-ALbuildLicensed -Feature 'Environments'
        if (-not $PSCmdlet.ShouldProcess($Name, 'Remove environment')) { return }

        Remove-BcContainer -Name $Name -DockerExecutable $DockerExecutable -Confirm:$false

        if ($TraefikConfigFolder) {
            $configFile = Join-Path $TraefikConfigFolder "$Name.json"
            if (Test-Path -LiteralPath $configFile) {
                Remove-Item -LiteralPath $configFile -Force
                Write-ALbuildLog "Removed Traefik configuration '$configFile'."
            }
        }
        Write-ALbuildLog -Level Success "Removed environment '$Name'."
    }
}