← Files Power BI DesktopARCHIVED FILE

scripts/Test-PowerBIReportLayoutBestPractices.ps1

1.24 KB · Oct 2, 2026 · 00:32 UTC

↓ Download file

param([string]$Path = ".", [string]$OutputPath, [switch]$Json)
$ErrorActionPreference = 'Stop'
$resolved = (Resolve-Path -LiteralPath $Path).Path
$jsonFiles = @(Get-ChildItem -LiteralPath $resolved -Recurse -File -Include page.json,report.json,pages.json -ErrorAction SilentlyContinue)
$findings = New-Object System.Collections.Generic.List[object]
if ($jsonFiles.Count -eq 0) { $findings.Add([pscustomobject]@{ severity = 'Info'; source = 'report'; message = 'No PBIP report JSON found. Export report to PBIP for native layout analysis.' }) }
foreach ($file in $jsonFiles) {
    $text = Get-Content -Raw -LiteralPath $file.FullName
    $visualMarkers = ([regex]::Matches($text, '"visual|visualType|displayName"')).Count
    if ($visualMarkers -gt 20) { $findings.Add([pscustomobject]@{ severity = 'Medium'; source = $file.Name; message = 'High visual density detected.' }) }
}
$result = [pscustomobject]@{ schema = 'codex.powerbi.reportLayoutBestPractices.v1'; root = $resolved; generated = (Get-Date).ToString('s'); findingCount = $findings.Count; findings = @($findings.ToArray()) }
if ($Json) { $text = $result | ConvertTo-Json -Depth 6; if ($OutputPath) { Set-Content -LiteralPath $OutputPath -Value $text -Encoding UTF8 }; $text; return }
$result

SHA-256: c2fc34bb2d51dbddf6eba570169e7ecbee672d1e7581897e6e679f0bfdb04d2c