import { Callout } from "zudoku/ui/Callout";

# Environments module

**Module:** `businessdev.ALbuild.Environments` &nbsp;•&nbsp; **Tier:** Licensed &nbsp;•&nbsp; **Cmdlets:** 4

The **Environments** module provisions and tears down demo/dev environments and cleans up expired ones. This is a **licensed** feature.

<Callout type="caution" title="Licensing">
Cmdlets in this module are part of a licensed tier and call `Assert-ALbuildLicensed` on entry. Without a valid ALbuild license they fail with clear remediation guidance. See [Licensing & tiers](../concepts/licensing).
</Callout>

## Cmdlets in this module

| Cmdlet | Description |
| --- | --- |
| [`Get-BcEnvironment`](#get-bcenvironment) | Lists ALbuild-provisioned Business Central environments (containers). |
| [`New-BcEnvironment`](#new-bcenvironment) | Provisions a demo or developer Business Central environment (container) with Traefik routing (licensed). |
| [`Remove-BcEnvironment`](#remove-bcenvironment) | Removes an ALbuild Business Central environment and its Traefik configuration (licensed). |
| [`Remove-BcExpiredEnvironment`](#remove-bcexpiredenvironment) | Removes all expired ALbuild Business Central environments (licensed). |

---

## Get-BcEnvironment

Lists ALbuild-provisioned Business Central environments (containers).

Returns the containers tagged as ALbuild environments, with their metadata labels (type,
owner, public URL, expiry) and whether they have expired.

### Syntax

```powershell
Get-BcEnvironment
    [-Name <String>]
    [-DockerExecutable <String>]
```

### Parameters

| Parameter | Type | Required | Description |
| --- | --- | :---: | --- |
| `-Name` | String | No | Optional exact environment name filter. |
| `-DockerExecutable` | String | No | The Docker executable to use (default 'docker'). **Default:** `'docker'`. |

### Output

PSCustomObject with Name, Type, Owner, Url, ExpiresAt, Expired, Running.

---

## New-BcEnvironment

Provisions a demo or developer Business Central environment (container) with Traefik routing (licensed).

Creates a Business Central container tagged with environment metadata labels (expiry, owner,
type) for label-based lifecycle management, and produces a Traefik v3 dynamic configuration
routing to it (Subdomain or PathPrefix). Requires Windows + Docker and a valid ALbuild
license.

### Syntax

```powershell
New-BcEnvironment
    -Name <String>
    -Domain <String>
    -Credential <PSCredential>
    [-ArtifactUrl <String>]
    [-Type <String>]
    [-Country <String>]
    [-Version <String>]
    [-Routing <String>]
    [-EnvironmentType <String>]
    [-ExpiresInDays <Int32>]
    [-OwnerEmail <String>]
    [-TraefikConfigFolder <String>]
    [-DockerExecutable <String>]
```

### Parameters

| Parameter | Type | Required | Description |
| --- | --- | :---: | --- |
| `-Name` | String | Yes | Environment / container name. |
| `-Domain` | String | Yes | Base domain for Traefik routing (e.g. businesscentral.example.com). |
| `-Credential` | PSCredential | Yes | Container admin credential. |
| `-ArtifactUrl` | String | No | The BC artifact URL. If omitted, resolved from -Type/-Country/-Version. |
| `-Type` | String | No | Artifact type when resolving: Sandbox (default) or OnPrem. **Allowed values:** `Sandbox`, `OnPrem`. **Default:** `'Sandbox'`. |
| `-Country` | String | No | Artifact country. Default 'w1'. **Default:** `'w1'`. |
| `-Version` | String | No | Optional artifact version. |
| `-Routing` | String | No | Traefik routing mode: Subdomain (default) or PathPrefix. **Allowed values:** `Subdomain`, `PathPrefix`. **Default:** `'Subdomain'`. |
| `-EnvironmentType` | String | No | Demo (default) or Development. **Allowed values:** `Demo`, `Development`. **Default:** `'Demo'`. |
| `-ExpiresInDays` | Int32 | No | Lifetime in days (used for the expiry label). Default 7. **Default:** `7`. |
| `-OwnerEmail` | String | No | Owner email recorded as a label. |
| `-TraefikConfigFolder` | String | No | Folder to write the Traefik dynamic configuration to. Default: ./traefik. **Default:** `(Join-Path (Get-Location) 'traefik')`. |
| `-DockerExecutable` | String | No | The Docker executable to use (default 'docker'). **Default:** `'docker'`. |

### Output

PSCustomObject describing the environment (Name, Url, ExpiresAt, Container, TraefikConfig).

---

## Remove-BcEnvironment

Removes an ALbuild Business Central environment and its Traefik configuration (licensed).

### Syntax

```powershell
Remove-BcEnvironment
    -Name <String>
    [-TraefikConfigFolder <String>]
    [-DockerExecutable <String>]
```

### Parameters

| Parameter | Type | Required | Description |
| --- | --- | :---: | --- |
| `-Name` | String | Yes | Environment / container name. |
| `-TraefikConfigFolder` | String | No | Folder containing the environment's Traefik dynamic config (&lt;Name>.json) to delete. |
| `-DockerExecutable` | String | No | The Docker executable to use (default 'docker'). No ConfirmImpact='High': ALbuild runs primarily non-interactively, where a High-impact prompt has no host UI and ShouldProcess throws a NullReferenceException. -WhatIf/-Confirm remain available. **Default:** `'docker'`. |

---

## Remove-BcExpiredEnvironment

Removes all expired ALbuild Business Central environments (licensed).

Finds ALbuild environments whose expiry has passed and removes them (and their Traefik
configuration). Intended to be run on a schedule.

### Syntax

```powershell
Remove-BcExpiredEnvironment
    [-TraefikConfigFolder <String>]
    [-DockerExecutable <String>]
```

### Parameters

| Parameter | Type | Required | Description |
| --- | --- | :---: | --- |
| `-TraefikConfigFolder` | String | No | Folder containing the environments' Traefik dynamic configs to delete. |
| `-DockerExecutable` | String | No | The Docker executable to use (default 'docker'). **Default:** `'docker'`. |

### Output

The names of the removed environments.

---
