← Files Power BI DesktopARCHIVED FILE
scripts/New-PowerBIDataContract.ps1
1.33 KB · Oct 2, 2026 · 00:32 UTC
param([string]$Path = ".", [string]$OutputPath, [switch]$Json)
$ErrorActionPreference = 'Stop'
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$contracts = & (Join-Path $scriptRoot 'New-PowerBIKpiTrustContract.ps1') -Path $Path -Json | ConvertFrom-Json
$items = foreach($c in @($contracts.contracts)){[pscustomobject]@{name=$c.measure; type='KPI'; owner=$c.owner; grain=$c.grain; sourceSystem=$c.sourceSystem; freshnessSla=$c.sla; breakingChangeRules=@('Rename requires downstream approval','Expression change requires expectation tests','Risk increase blocks release'); publishCriteria=@('Trust score reviewed','Owner assigned','Acceptance test present'); testQuery=("EVALUATE ROW(`"{0}`", [{0}])" -f $c.measure)}}
$result=[pscustomobject]@{schema='codex.powerbi.dataContract.v1'; generated=(Get-Date).ToString('s'); contractCount=@($items).Count; contracts=@($items)}
if($Json){$text=$result|ConvertTo-Json -Depth 10; if($OutputPath){Set-Content -LiteralPath $OutputPath -Value $text -Encoding UTF8}; $text; return}
$md=@('# Power BI Data Contracts','')+@($items|ForEach-Object{"## $($_.name)`n- Owner: $($_.owner)`n- Grain: $($_.grain)`n- SLA: $($_.freshnessSla)`n"})
$content=($md -join [Environment]::NewLine)+[Environment]::NewLine; if($OutputPath){Set-Content -LiteralPath $OutputPath -Value $content -Encoding UTF8}; $content
SHA-256: d6021e2eca6c0615d6a590a479bbb5b216d9d85b1ceeec87b41ac9ce53ac8df2