Public/New-TenantLensDocumentation.ps1

function New-TenantLensDocumentation {
    <#
    .SYNOPSIS
        Generates Markdown tenant documentation from a snapshot.
    .DESCRIPTION
        The output is deterministic and diff-friendly, so it can be committed
        to a customer wiki or git repository and kept current by re-running.
    .EXAMPLE
        New-TenantLensDocumentation -SnapshotPath .\out\contoso_2026-07-23_1430
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position = 0)]
        [string]$SnapshotPath,

        # Target file (defaults to documentation.md in the snapshot run folder).
        [string]$OutputPath,

        # Also return the Markdown string.
        [switch]$PassThru
    )

    $snapshot = Read-TLSnapshot -Path $SnapshotPath
    $markdown = Format-TLDocumentation -Snapshot $snapshot

    if (-not $OutputPath) {
        $runFolder = $snapshot._Path
        if ((Split-Path -Path $runFolder -Leaf) -eq 'snapshot') { $runFolder = Split-Path -Path $runFolder -Parent }
        $OutputPath = Join-Path -Path $runFolder -ChildPath 'documentation.md'
    }

    Write-TLFile -Path $OutputPath -Content $markdown
    Write-Verbose ("Documentation written to '{0}'." -f $OutputPath)

    if ($PassThru) { return $markdown }
    return Get-Item -Path $OutputPath
}